import java.util.Scanner;

public class LLPQueue
{
Node head = null;

  public void insert(int value)
  {
    Node n = new Node(value,null);
    if(isEmpty())        			 //if not empty
        head = n;
    else
    {
        Node temp = head;
        while(temp.next != null)
            temp = temp.next;
        temp.next = n;
    }
    Node b = head, c;
    int a;
    for(b = head; b != null; b = b.next)
      for(c = b.next;c != null; c = c.next)
        if(b.info > c.info)
        {
          a = b.info;
          b.info = c.info;
          c.info = a;
        }
  }
  public int remove()
  {
    if(isEmpty())
    {
      System.out.println("Stack underflow");
      System.exit(1);
    }
    int value = head.info;
    Node temp = head;
    head = head.next;
    temp = null;
    return value;
  }
  private boolean isEmpty()
  {
    return head == null;
  }
  public String toString()
  {
    Node temp = head;
    String q = "[ ";
    while(temp != null)
    {
      q = q + temp.info + " ";
      temp = temp.next;
    }
    q = q + "]";
    return q;
  }
  public static void main(String[] args)
  {
    LLPQueue l = new LLPQueue();
    int i,item;
   do{
       System.out.println("Choose an option");
       System.out.println("1.insert  2.delete  3.exit");
       Scanner sc = new Scanner(System.in);
       i = sc.nextInt();
       switch(i)
       {
          case 1:
               System.out.println("Enter item to push");
               item = sc.nextInt();
               l.insert(item);
               System.out.println(l);
               break;
          case 2:
               l.remove();
               System.out.println(l);
               break;
          case 3:
              break;
          default:
              System.out.println("wrong input");
       }
   }while(i!=3);
  }
}
