C++ PROGRAM FOR CIRCULAR LINKED LIST USING POINTER


#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int info;
node * link;
};
class qp
{
int delmnt;
int temp;
node * f,*r;
public:
qp()
{
f=r=NULL;
}
void insert();
void dele();
void display();
};
void qp::insert()
{
if(r==NULL)
{
node *p;
p=new node;
cout<<"enter the element to be insert:\n";
cin>>p->info;
cout<<"element is inserted:\n";
p->link=NULL;
r=f=p;
}
else
{
node *p;
p=new node;
cout<<"enter the element to inserted";
cin>>p->info;
cout<<"element is inserted";
r->link=p;r=p;
}
}
void qp::display()
{
node *curq=f;
while(curq!=r)
{
cout<<curq->info;
curq=curq->link;
}
cout<<curq->info;
}
void qp::dele()
{
node *temp;
if(f==NULL)
{
cout<<"queue is empty";
exit;
}
temp=f;
delmnt=f->info;
cout<<"deleted element is\n";
cout<<delmnt;
if(r==f)
r=f=NULL;
else
f=f->link;
delete(temp);
}
void main()
{
clrscr();
qp ob;
int ch;
clrscr();
cout<<"\n menu\n1.insert\n2.delete\n3.display\n4.exit\n";
while(ch<=4)
{
cout<<"\n enter the choice:";
cin>>ch;
switch(ch)
{
case 1:
ob.insert();
break;
case 2:
ob.dele();
break;
case 3:
 ob.display();
 break;
 case 4:
 cout<<"\n exit";
 exit(0);
 }
 }
 getch();
 }

OUTPUT:
CIRCULAR LINKED LIST USING POINTER

 menu
1.insert
2.delete
3.display
4.exit

 enter the choice:1
enter the element to be insert:
12
element is inserted:

 enter the choice:1
enter the element to inserted20
element is inserted
 enter the choice:1
enter the element to inserted30
element is inserted
 enter the choice:3
122030
 enter the choice:2
deleted element is
12
 enter the choice:3
2030
 enter the choice:4

 exit
























No comments:

Post a Comment