I have a serious problem with my Binary Search Tree and the Ofstream object.

Here's the app.

http://pastebin.com/gUZpHPfs

Here's the header.

http://pastebin.com/DZfcxYyz

and Here's the implementation.

http://pastebin.com/vXtxH4MB

It's for a coding class and I can't for the life of me figure out where I went wrong. It wont print the tree to file and the tree only saves the first element. Any ideas what I did wrong?

Excuse some of my comments.. haha

Also I posted it to pastebin, since this has a character limit.
I'm sure there are a plethora of problems with your code from a logic and and certainly from a design standpoint.

But, you might begin with BST::Insert which only adds a node correctly when Root is null, otherwise it leaks memory. Ask yourself: when Root is not null, where is a node higher up in the tree set to point to temp?

Also I posted it to pastebin, since this has a character limit.

The recommended course of action is to reduce the code to a minimal, compilable example which still reproduces your issue.

Also, in case you're wondering about the output in the generated file, you don't count nodes correctly, and "Height" is not found by calling BST::findMax.

This code is a great example of why testing as you are developing is a good practice.
Last edited on
Topic archived. No new replies allowed.