I tried to implement BST in C ++. This is a special member function that executes when traversing an order and returns a vector with tree elements. Now the problem is with the pop () function of the stack that I installed for the current node.
void value not ignored as it ought to be
I understand that an empty stack will return an empty value after the previous call to pop (). But what is the solution to this problem, since in this workaround algorithm, you need to remove the last node from the stack.
vector <int> BSTree::in_order_traversal() { vector <int> list; stack <Node *> depthStack; Node * cur = root; while ( !depthStack.empty() || cur != NULL ) { if (cur != NULL) { depthStack.push(cur); cur = cur->left; } else { cur = depthStack.pop();
source share