简体   繁体   中英

C# binary search tree - stack overflow - debug

I am a newbie learning C# after C++. VS2010.

Trying to debug my code, I come across weird empty lines in the "locals" frame. The debugger just quits after a few seconds of me staring at these empty lines.

Please check it out: http://pastebin.com/KZbfy8JF

Thanks.

I've spent at least 3 hours looking for solutions and playing around with code to no avail.

Value属性getter和setter是无限递归的 - 将它们更改为:

public T Value { get; set; }

Already answered (Value get/set) but here is a tip:

In VS.NET, press CTRL+ALT+E to open the Exceptions dialog (depending on your profile selected in VS.NET, it may be under Debug->Exceptions as well). This lets you break when certain exception types are thrown, as opposed to the full stack unwinding and the program ultimately crashing.

For "Common Language Runtime Exceptions" check the "Thrown" checkbox, hit OK, then run your program. The execution of your program will stop at the point of exception, which should make it much more obvious.

In your case, the program breaks on your property. To see more, open the Call Stack wndow (Debug->Windows->Call Stack or CTRL+ALT+C) to see the full stack and you'll see your property is just about the only thing in it.

Ok generally, stack overflow would mean that you're recursing without going back. I don't see however where you do that. What I'd do would be to insert a Console.WriteLine statement in a few strategic places to see which lines are executed and how often. For example, on the beginning of Insert, and in the inner loop. This should give you (and us ;) a bit more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM