Blogger news

Followers

Saturday, October 26, 2013
//Courtesy : Avinash G, Computer Science Dept.,Srinivas Institute of Technology,Mangalore

----
#include<iostream.h>
#include<conio.h>
#include<process.h>

class list
{
                struct node
                {
                int info;
                struct node *next;
                };
                struct node *plist;
public:
list()
{
plist=NULL;
}
void insert(int);
void del();
void display();
};
void main()
{
 list a;
 int choice,item;
 clrscr();
 while(1)
 {
  cout<<"option are 1.insert 2.delete 3.display 4.exit\n";
  cout<<"enter your choice\n";
  cin>>choice;
                switch(choice)
                {
                case 1: cout<<"enter the element to be inseted\n";
                                cin>>item;
                                a.insert(item);
                                break;
                case 2: a.del();
                                break;
                case 3: a.display();
                                break;
                case 4:exit(0);
                }
  }
 }
void list::insert(int item)
{
                struct node *p;
                p=new (node);
                p->info=item;
                p->next=plist;
                plist=p;
}
void list::del()
{
struct node *t;
int item;
if(plist==NULL)
                cout<<"list is empty\n";
else
 {
                t=plist;
                item=t->info;
                cout<<"item removed is  "<<item<<"\n";
                plist=t->next;
                delete(t);
 }
}
void list::display()
{
struct node *temp;
if(plist==NULL)
                cout<<"list is empty\n";
else
{
                cout<<"list elements are ";
                for(temp=plist;temp!=NULL;temp=temp->next)
                                cout<<temp->info<<"\t";
                cout<<endl;
}
}
Program Ends

Screen shot:

<![if !vml]><![endif]>



0 comments: