Exemple #1
0
void iot(struct node * ptr){
    if(ptr->left != NULL){
        iot(ptr->left);
    }
    printf("%s\t\t\t%d\t\t\t%d\n", ptr->data, ptr->occurances, ptr->versions);
    if(ptr->right != NULL){
        iot(ptr->right);
    }
    return;
}
        vector<int> inorderTraversal(TreeNode *root) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            vector<int> iot(0);//inorder traversal
            if (root == NULL){
                return iot;
            }
            stack<TreeNode*> stk;
            TreeNode * current = NULL;
            bool left_child_visited = false;
            stk.push(root);
            while (!stk.empty()){
                current = stk.top();
                stk.pop();
                if (current->left == NULL || left_child_visited){
                    iot.push_back(current->val);
                    if (current->right){
                        stk.push(current->right);
                        left_child_visited = false;
                    }else{
                        left_child_visited = true;
                    }

                }else{
                    stk.push(current);
                    stk.push(current->left);
                    left_child_visited = false;
                }
            }
            return iot;

        }