Okay so we are talking about binary trees in class and were told to practice. This is based off of (and is very close to) code that our teacher gave us in class, so I am hoping this is just some typo and that I am not a complete dunce. However, he was writing it on the board and never typed it up and compiled it.
To my knowledge, this should just generate random numbers, insert them in a binary tree, and then the traverse function should print them out.
When I compile everything goes fine but when I run the program it just says "Segmentation fault (core dumped)." I tried a google search but most of what I found assumes you have some sort of debugging software, which we don't. What am I missing?
$ g++ -W{all,extra,pedantic} foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:31:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
foo.cpp:36:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
You're using assignment = operator in your conditional statements, instead of the comparison operator ==. Which is what the debug output @ne555 posted is complaining about.
That was the problem, however now I have another. I have two different traversal functions coded at this point, one recursive and one not, but both only return two numbers and then stop. They are coded almost exactly as the professor's functions, but for some reason his works and mine does not. Currently the recursive traversal function is commented out, but I have tried both of them and they each print two numbers when they should print the entire tree.