<br />#include<iostream> #include<conio.h> using namespace std; struct queue { int data; struct queue *link; }*front,*rear,*temp,*ptr; void insert() { int ele; cout<<"Enter element to be inserted:"<<endl; cin>>ele; temp=new queue; if(temp==NULL) cout<<"Out of Memory !! Overflow !!!"<<endl; else { temp->data=ele; temp->link=NULL; if(front==NULL) { front=rear=temp; } else { rear->link=temp; rear=temp; } cout<<"Element has been inserted at end:"<<endl; } } int Delete() { int info; if(front==NULL) { cout<<"Underflow !!!"<<endl; return 0; } else { temp=front; info=front->data; if(front==rear) { rear=NULL; } front=front->link; temp->link=NULL; delete temp; cout<<info<<" deleted from queue:"<<endl; } } void display() { if(front==NULL) { cout<<"Empty Queue !!!"<<endl; } else { ptr=front; cout<<"front->"; while(ptr) { cout<<"[ "< data<<" ]->"; ptr=ptr->link; } cout<<"rear"; } } int main() { int opt,elem; front=rear=NULL; cout<<"\n ### Linked List Implementation of QUEUE Operations ### \n"; do { cout<<"\n Press 1-Insert, 2-Delete, 3-Display, 4-Exit\n"; cout<<"\n Your option ? "; cin>>opt; switch(opt) { case 1: insert(); break; case 2: Delete(); break; case 3: cout<<"Linked List Implementation of Queue: Status:\n"; display(); break; case 4: cout<<"\n Terminating n"; break; default: cout<<"\nInvalid Option !!! Try Again !! \n"; break; } cout<<"\n Press a Key to Continue . . . "; getch(); }while(opt != 4); getch(); return 0; }
corollary :
You must be logged in to post a comment.