I am a beginner programmer going to school. I am having a tough time trying to write my binary tree into a file. I figured out how to read a file to a binary tree but I am not sure how to right it back in. What I was seeing in the forums it only shows one variable and I've tried to adjust it to my variables which I cannot figure it out. Below is my source code. If anyone could help me understand how to write a binary search tree into a file that would be awesome! Thank you in advance.
The problem is at line 103. You open the file for each node written, which means that each node writes at the beginning of the file. Open the file in writeToFile and pass the stream to write_node(). Something like:
The problem is at line 103. You open the file for each node written, which means that each node writes at the beginning of the file. Open the file in writeToFile and pass the stream to write_node().
That is not entirely correct. write_node is NOT a recursive function.
The function calls inorder() recursively, but inorder() does not write data into a file.