/* 2. Write a C++ program to create a class LIST (linked list) with insert at front, and delete from front as member functions. Demonstrate all functions after creating a list object. */

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
    int info;
    struct node *next;
};
typedef struct node *llist;
class LIST
{
    llist start;

    public:
        LIST()    
        {
            start = NULL;
        }
        void InsFront();
        void DelFront();
        void Display();
};
void LIST::InsFront()
{
    llist temp;
    temp = new node;
    cout<<"\nEnter the item to insert in the list : ";
    cin>>temp->info;
    temp->next = start;
    start = temp;
}
void LIST::DelFront()
{
    llist temp;
    if (start == NULL)
        cout<<"\nERROR : No items in the list";
    else
    {
        temp = start;
        start = start->next;
        cout<<"\nDeleted item is "<<temp->info;
        delete temp;
    }
}
void LIST::Display()
{
    llist temp;
    if (start == NULL)
        cout<<"\nERROR : List is empty";
    else
    {
        temp = start;
        cout<<"\nContents of List is as follows :\n";
        while (temp != NULL)
        {
            cout<<temp->info<<"\t";
            temp = temp->next;
        }
    }
}
void main()
{
    LIST a;
    int ch;
    clrscr();    
    while(1)
    {
        cout<<"\nMENU\n1. Insert Front\n2. Delete Front\n3. Display\n4. Exit";
        cout<<"\nYour Choice = ? ";
        cin>>ch;
        switch(ch)
        {
            case 1:
                a.InsFront();
                break;

            case 2:
                a.DelFront();
                break;

            case 3:
                a.Display();
                break;

            case 4:
                exit(0);

            default:
                cout<<"\nInvalid Choice. Try again";
        }
    }
}