Question: Write a c++ program that: This is what I have: vector inorderTraversal(TreeNode *root) { vector result; stack s; const TreeNode *p = root; while (!s.empty()
Write a c++ program that:
This is what I have:
vector
{
vector
stack
const TreeNode *p = root;
while (!s.empty() || p != nullptr)
{
if (p != nullptr)
{
s.push(p);
p = p->left;
}
else
{
p = s.top();
s.pop();
result.push_back(p->value);
p = p->right;
}
}
return result;
}
Given a binary tree, return the inorder traversal of its nodes values using a stack. Given binary tree [1,null,2,3], return [1,3,2].
For my program, it only returns

With this main:
1 2 Program ended with exit code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
