Recursive modification of map

I am having trouble with recursively modifying a <string, int> map (NCPB) -- when I call for what should be existing values in the map, I get "junk" values back (integers, but sometimes negative, large numbers, etc.). I've posted only the problematic function here:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````int Count_Noncrossing(string RNA, map &NCPB) { map ::iterator it; if (RNA.length() <= 2)//perfect short interval can only have 1 match; return 1 { return 1; } it = NCPB.find(RNA); if (it != NCPB.end()) { return it->second; //return it if already calculated } //Determine legal places to "split" RNA vector splits; for (int j = 1; j<(int)RNA.length(); j=j+2) { if (Perfect_Interval (RNA.substr(j+1)) && Bonding (RNA.substr(0,1), RNA.substr(j,1))) { splits.push_back(j); } } //Calculate Noncrossing Matches over each subinterval it = NCPB.find(RNA); int sum = 0; if (it == NCPB.end()) {sum = 0;} else sum = it->second; for (int j = 0; j<(int)splits.size(); ++j) { int first_part = Count_Noncrossing(RNA.substr(1,splits[j]-1), NCPB); int second_part = Count_Noncrossing(RNA.substr(splits[j]+1), NCPB); sum += first_part * second_part; } NCPB [RNA] = sum; return it->second; }``````

The problem is that when I ask for existing map values in a subsequent recursive call, they don't seem to be there. I imagine I'm missing something straightforward but can't seem to find it. Anybody have any ideas? I've tried declaring the map globally, passing it (as shown above), nothing seems to help. Thanks in advance!
The problem is on line 39: `it` is likely to be invalid. Why don't you return `sum`?
Lines 9-13. If RNA was fount in NCPB, you are terminating function.

Line 26: you search for RNA in NCPB again. It this time you are guaranteed to have it point to end of container if execution had come to this place.

line 39: you are dereferencing an end iterator which is illegal.
Thanks everybody; I'll give that a try.
Topic archived. No new replies allowed.