Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by nisarg ( 6 years ago )
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct node
{
    int data;
    struct node *next;
}*list=NULL,*p,*q,*r,*s,*temp;

class singly_39
{
    public:
    int choice;
        singly_39()
        {
            menu();
        }
        void menu()
        {
            do
            {
                cout<<"Choose any Option \n1.Insert at beginning \n2.Insert at last\n3.Insert before a position \n4.Insert after a position \n5.Delete at beginning \n6.Delete at last \n7.Delete at a position \n8.Sort \n9.Count \n10.Reverse \n11. Display \n12.Exit "<<endl;
                cout<<"Enter your choice : ";
                cin>>choice; 
                switch (choice)
                {
                    case 1:
                        insertb();
                        break;
                    case 2:
                        inserte();
                        break;
                    case 3:
                        insertbp();
                        break;
                    case 4:
                        insertbp();
                        break;
                    case 5:
                        deleteb();
                        break;
                    case 6:
                        deletee();
                        break;
                    case 7:
                        deletep();
                        break;
                    case 8:
                        sort();
                        break;
                    case 9:
                        count();
                        break;
                    case 10:
                        reverse();
                        break;
                    case 11:
                        display();
                        break;
                    case 12:
                        cout<<"thank uuuuuuu";
                        break;
                    
                    default:
                        break;
                }
            }while(choice!=12);
            
        }
        void insertb()
        {
            cout<<endl<<"Enter The Element You Want To Insert : "<<endl;
            int val;
            cin>>val;
            p=(struct node*) malloc(sizeof(node));
            p->data=val;
            if(list==NULL)
            {
                p->next=NULL;
                list=p;
            }
            else
            {
                p->next=list;
                list=p;
            }

        }
        void inserte()
        {
            cout<<endl<<"Enter The Element You Want To Insert : "<<endl;
            int val;
            cin>>val;
            p=(struct node*) malloc(sizeof(node));
            p->data=val;
            if(list==NULL)
            {
                p->next=NULL;
                list=p;
            }
            else
            {
                q=list;
                while(q->next==NULL)
                {
                    q=q->next;
                }
                q->next=p;
                p->next=NULL;
            }
        }
        void insertbp()
        {
            int key,value;
            cout<<endl<<"Enter the key element";
            cin>>key;
            cout<<"Enter The Element You Want To Insert : ";
            cin>>value;
           
            p=(struct node*) malloc(sizeof(node));
            p->data=value;
          
            if(list==NULL)
            {
                cout<<"List is Empty";
            }
            else
            {
                q=list;
                while(q->next!=NULL && q->data != key)
                {
                    r=q;
                    q=q->next;
                }         
                if(q->data==key)
                {   
                    r->next=p;
                    p->next=q;
                }
                else
                {
                        cout<<"Data not found";
                }
            }
        }
        void insertap()
        {
            
            int key,value;
            cout<<endl<<"Enter the key element";
            cin>>key;
            cout<<"Enter The Element You Want To Insert : ";
            cin>>value;
           
            p=(struct node*) malloc(sizeof(node));
            p->data=value;
          
            if(list==NULL)
            {
                cout<<"List is Empty";
            }
            else
            {
                q=list;
                while(q->next!=NULL && q->data != key)
                {
                    r=q;
                    q=q->next;
                }         
                if(q->data==key)
                {   
                    r->next=p;
                    p->next=q;
                }
                else
                {
                        cout<<"Data not found";
                }
            }
        }
        void deleteb()
        {
            if(list==NULL)
            {
                cout<<"List is Empty";
            }
            else
            {
                q=list;
                list=list->next;
                free(q);
            }
        }
        void deletee()
        {
            
            if(list==NULL)
            {
                cout<<"List is Empty";
            }
            else
            {
                q=list;
                while(q->next!=NULL)
                {
                    r=q;
                    q=q->next;
                }
                r->next=NULL;
                free(q);
            }
        }
        void deletep()
        {
            int key;
            cout<<endl<<"Enter the key element";
            cin>>key;
            if(list==NULL)
            {

            }
        }
        void sort()
        {
            
        }
        void count()
        {
            
        }
        void reverse()
        {
            
        }
        void display()
        {
            if(list==NULL)
            {
                cout<<"List is Empty ";
            }
            else
            {
                q = list;
                while (q != NULL)
                {
                    cout<< q->data <<"----->";
                    q = q->next;
                }
                cout<<endl;
            }
        }
};
int main()
{
    singly_39 a;
    return 0;
}

 

Revise this Paste

Your Name: Code Language: