c# - Unable to step-in to Recursive function breakpoint VS2013 -
i trying convert method loops recursion part of coding kata practices(trying solve problems recursive approach). there's nothing in logic
- the breakpoint not being hit anywhere in recursive method.
- i tried place logger(console output) check if method called nothing being logged.
here's method definition(s):
// original method loop public ienumerable<tuple<int, int>> getelementwithlargestdeltaontimeline(int[] a) { int runninglindex = 0; int currlvalue = a[0]; int runninghindex = 1; int currhvalue = a[1]; int currdelta = 0; (int = 1; < a.length - 1; i++) { if (a[i] < currlvalue) { currlvalue = a[i]; runninglindex = i; } (int j = runninglindex + 1; j < a.length; j++) { if ((a[j] - currlvalue) > currdelta) { currdelta = a[j] - currlvalue; runninghindex = j; currhvalue = a[j]; } } } yield return new tuple<int, int>(currlvalue, runninglindex); yield return new tuple<int, int>(currhvalue, runninghindex); }
recursive -
// trying above method convert recursive, // note - may not correct *shy* problem why it's not doing anything(not step through/logging) public ienumerable<tuple<int, int>> getelementwithlargestdeltaontimelinerec (int[] a, int i, int j, int runninglindex, int currlvalue, int runninghindex, int currhvalue, int currdelta) { console.writeline("iteration i-{0}: j-{1} runninglindex-{2} currlvalue-{3} runninghindex-{4} currhvalue-{5} currdelta-{6}" , i, j, runninglindex, currlvalue, runninghindex, currhvalue, currdelta); if (i < a.length) { if (a[i] < currlvalue) { currlvalue = a[i]; runninglindex = i; } if (j < a.length) { if ((a[j] - currlvalue) > currdelta) { currdelta = a[j] - currlvalue; runninghindex = j; currhvalue = a[j]; } getelementwithlargestdeltaontimelinerec(a, i, j++, runninglindex, currlvalue, runninghindex, currhvalue, currdelta); } } else { yield return new tuple<int, int>(currlvalue, runninglindex); yield return new tuple<int, int>(currhvalue, runninghindex); } getelementwithlargestdeltaontimelinerec(a, i++, runninglindex + 1, runninglindex, currlvalue, runninghindex, currhvalue, currdelta); yield break; }
main -
public class program { public static void main() { var = new[] { 10, 9, 3, 6, 7, 8, 15, 10, 6 }; var val = new stockmanager(); var result = val.getelementwithlargestdeltaontimelinerec(a, 0, 0, 0, a[0], 1, a[1], 0); } }
question(s) -
- does recursive method calls something(incorrect) causing issue?
- why method not being called , returning empty result without failing/error/warning?
additional info - .net 4.5, visual studio 2013
i tried running code on different machine(just verify if wrong vs instance).
there little trick methods return ienumerable
. should enumerate them!
instead of calling getelementwithlargestdeltaontimelinerec
inside should enumerate , yield return elements or store result use later. ienumerable
s nothing until enumerated.
foreach (var e in getelementwithlargestdeltaontimelinerec(...)) yield return e;
or
var innerresult = getelementwithlargestdeltaontimelinerec(...);
and use innerresult
somehow cause enumerated.
Comments
Post a Comment