hi, there.
I am not sure how to build the tree with values:
Everything should be right except the main(). How to demonstrate this program correctly?Code:struct Node *root = 1 root->left = 2 root->right = 3 root->left->left = 4; root->left->right = 5;
Code:#include <iostream> #include<stdio.h> #include<stdlib.h> #include <stack> // std::stack using namespace std; struct Node { char value; Node* left; Node* right; }; void Visit(Node* node) { cout << node->value; } void InorderTraversal(Node* root) { stack<Node*> s; Node* current = root; while (current != NULL) { s.push(current); current = current->left; } while (!s.empty()) { current = s.top(); s.pop(); Visit(current); current = current->right; while (current != NULL) { s.push(current); current = current->left; } } } int main() { /* Constructed binary tree is 1 / \ 2 3 / \ 4 5 */ struct Node *root = 1 root->left = 2 root->right = 3 root->left->left = 4; root->left->right = 5; InorderTraversal(root); return 0; }