public static void nonRecursiveInorder(Node node)
{
Stack<Node> st=new Stack();
st.push(node);
Node temp;
while(!st.isEmpty())
{
temp=st.peek();
if(temp.left!=null && temp.left.visited==false)
st.push(temp.left);
else
{
if(temp.left==null && temp.right!=null && temp.right.visited==false)
{
System.out.print(" "+temp.value);
temp.visited=true;
st.pop();
st.push(temp.right);
}
else
{
if(temp.left!=null && temp.left.visited==true && temp.right!=null && temp.right.visited==false)
{
System.out.print(" "+temp.value);
temp.visited=true;
st.pop();
st.push(temp.right);
}
else
{
System.out.print(" "+temp.value);
temp.visited=true;
st.pop();
}
}
}
}
}
sbharathind 0 Newbie Poster
sbharathind 0 Newbie Poster
tux4life 2,072 Postaholic
devinnrock -3 Newbie Poster
tux4life commented: Signature spammer. -3
tux4life 2,072 Postaholic
sbharathind 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.