//Linked Stack
class Node
{   int info;
    Node next;
}
public class StackLinked
{   Node top;
    StackLinked()
    {   top=null;
    }
    //************************
    void push(int n)
    {   Node temp=new Node();
        if(temp==null)
        {   System.out.println("Overflow");
            return;
        }
        temp.info=n;
        temp.next=null;
        if(top==null) top=temp;
        else
        {   temp.next=top;
            top=temp;
        }
    }//push
    //************************
    int pop()
    {   if(top==null)
        {   System.out.println("Underflow");
            return 0;
        }
        int temp=top.info;
        top=top.next;
        return temp;
    }//pop
    //************************
    int peek()
    {   return top.info;
    }
    //************************
    void lifo()//traverse
    {   Node ptr=top;
        while(ptr!=null)
        {   System.out.print(ptr.info+" ");
            ptr=ptr.next;
        }
        System.out.println();
    }//lifo
    public static void main()
    {   StackLinked stack=new StackLinked();
        stack.push(5);
        stack.push(6);
        stack.push(7);
        stack.lifo();
        stack.pop();
        stack.pop();
        stack.push(5);
        stack.lifo();
    }
}//class lStack

