|
|
|
|
|
| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 13 Mar 2008 22:04:41 IST
|
|
|
//queue as linked list #include<iostream.h> #include<process.h> #include<conio.h> struct queue { int no; char name[20]; queue *link; void accept() { cout<<"Enter no. & name "; cin>>no>>name; } void output() { cout<<no<<" "<<name<<endl; } }; void qinsert(queue *&front,queue *&rear) { queue *temp; temp=new queue; temp->accept(); temp->link=NULL; if(rear==NULL) front=rear=temp; else { rear->link=temp; rear=temp; } } void qdelete(queue *&front) { if(front==NULL) cout<<"\nUnderflow\n"; else { queue *temp; temp=new queue; temp=front; temp->output(); front=front->link; delete temp; } } void qdisplay(queue *front,queue *rear) { if(front==rear) cout<<"\nQueue is empty\n"; else while(front) { front->output(); front=front->link; } } void main() { clrscr(); queue *front, *rear; front=new queue; front=NULL; rear=new queue; rear=NULL; int op; char ch; do { cout<<"\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"; cout<<"Enter your choice "; cin>>op; if(op==1) qinsert(front,rear); if(op==2) qdelete(front); if(op==3) qdisplay(front,rear); if(op==4) exit(0); cout<<"\nWant to continue? "; cin>>ch; }while(ch=='y'||ch=='Y'); }
|
|
this reply: 2 points
(with 0 
in 1 votes ) [?]
|
|
You have to be logged on to rate
|
|
|
|
|
|
|
|
|
|