import java.util.*;
public class SNode {
    int data;
    SNode next;
    public SNode(int data)
    {
        this.data=data;
        next=null;
    }
}
class LList
{
    private SNode start;
    public LList()
    {
        start=null;
    }
    public void insert(int ele)
    {
        SNode p=new SNode(ele);
        p.next=start;
        start=p;
    }
    public int delete()throws Exception
    {
        if(start==null)
            throw new Exception("Stack Linked List Empty");
        SNode p=start;
        start=start.next;
        return(p.data);
    }
    public void display()
    {
        if(start==null)
        {
            System.out.println("Stack Linked List");
            return;
        }
        SNode q=start;
        while(q!=null)
        {
            System.out.print(q.data+" ");
            q=q.next;
        }
        System.out.println();
    }
}
class LListExp
{
    public static void main(String args[])
    {
        Scanner src=new Scanner(System.in);
        LList obj=new LList();
        while(true)
        {
            int ele;
            System.out.println("Enter choice");
            System.out.println("1.Insert 2.Delete 3.Display 4.Exit");
            int ch=src.nextInt();
            if(ch==4)
                break;
            switch(ch)
            {
                case 1:System.out.println("Enter the element to insert");
                ele=src.nextInt();
                obj.insert(ele);
                obj.display();
                break;

                case 2:try
                {
                    ele=obj.delete();
                    System.out.println("Deleted element is: "+ele);

                }
                catch(Exception e)
                {
                    System.out.println(e);
                }
                obj.display();
                break;

                case 3:obj.display();
                break;

                default:System.out.println("INVALID CHOICE");
            }
        }
}
}

O/P:

Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
12
12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
23
23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
1
1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
34
INVALID CHOICE
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
45
45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
56
56 45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
67
67 56 45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
78
78 67 56 45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
2
Deleted element is: 78
67 56 45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
2
Deleted element is: 67
56 45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
2
Deleted element is: 56
45 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
2
Deleted element is: 45
1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
3
1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
1
Enter the element to insert
99
99 1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
2
Deleted element is: 99
1 23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
2
Deleted element is: 1
23 12 
Enter choice
1.Insert 2.Delete 3.Display 4.Exit
4
BUILD SUCCESSFUL (total time: 53 seconds)
