i have a project for my programming class where we have to create a binary search tree and then when the program exits we need to save the tree to a text file and then restore it when the program opens. the basic functions were given to us, but the textbook isnt clear on how to save and restore data to and from the text file. im just not sure where to put the code. would the restore code go in the trees constructor or do i need a seperate function to initialize all the nodes? also, because exit is a case statement, should i have the save function called in the case statement or after the loop finishes executing? any help would be appreciated, theres a lot of code which is why i didnt put it up, but i will if itll help
nightninja12
0
Newbie Poster
Recommended Answers
Jump to Postwould the restore code go in the trees constructor or do i need a seperate function to initialize all the nodes?
I would put it in a separate constructor, as well as a public method. The actual implementation could be in a private method that is shared between the two.
…
Jump to PostNot a traversal function. You want to be able to traverse without needing to write to file each time you do a traverse.
A separate save function is probably best. That gives you more control. In addition it allows you to save the entire tree or any subtree of …
All 5 Replies
Tom Gunn
1,164
Practically a Master Poster
nightninja12
0
Newbie Poster
Lerner
582
Nearly a Posting Maven
nightninja12
0
Newbie Poster
Lerner
582
Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.