inorder traversal without using recursion
inorder traversal without using recursion
vector<int> inOrder(Node* root)
{
vector<int>v;
stack<Node*>st;
while(root!=NULL || !st.empty())
{
while(root)
{
st.push(root);
root=root->left;
}
root=st.top();
st.pop();
v.push_back(root->data);
root=root->right;
}
return v;
}
Comments
Post a Comment