Binary Search Tree 2

Good evening to all seniors here. How to stop the program when user enter 0? I wish to do it by my own. I hope seniors here can give me rough idea on this. Its basically my assignment on implementing tree (BST) and i wish to complete by myself. In case i encountered a problem, i might post my codes here for senior's review. Thanks in advance.
How to stop the program when user enter 0?

First, your program must determine that the user entered 0. Then, you either return 0; if you are inside int main, or you may call std::exit(0); from anywhere.
http://www.cplusplus.com/reference/cstdlib/exit/
1
2
3
4
int value;
while ((cin << value && value != 0) {
    // do something with value;
}


The loop will run until (1) cin<< value is false, which means that the user entered a bad value, or you hit end of file etc, or (2) the value that gets read is zero.

Note that this relies on the fact that && is guaranteed to evaluate its left operand (cin << value) first.
+1 dhayden: This is exactly the type of loop I when I competed in ACM ICPCs
Topic archived. No new replies allowed.