/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideoenb
{
	public static Stack stack = new Stack();
	public static void main (String[] args) throws java.lang.Exception
	{
		// create some input
		Node head = new Node(1);
		head.left = new Node(2);
		head.right = new Node(3);
		head.right.left = new Node(4);
		
		iterativeInorder(head);
	}
	
	static void iterativeInorder(Node head)
	{
		Node current = head;
		while( current != null )
		{
			
			if( current.left != null && current.left.visited == false)
			{	
				stack.push( current );
				current = current.left;
				continue;
			}
			else
			{
				visit(current);
				current.visited = true;
			}
			
			if( current.right != null ) 
			{
				current = current.right;
			}
			else
			{
				if( ! stack.empty() )
				{
					current = (Node) stack.pop();	
				}
				else
				{
					current = null;
				}
				
			}
			
		}
	}
	
	static void visit(Node current)
	{
		System.out.println(current.value+"\n");
	}
}

class Node
{
	public Node left=null;
	public int value;
	public boolean visited=false;
	public Node right=null;
	
	public Node(int value)
	{
		this.value = value;
	}
}