IMPLEMENT INSERTION IN SINGULAR QUEUE USING LINKED LIST

/*PROGRAM TO IMPLEMENT INSERTION OPERATION IN SINGULAR QUEUE USING LINKED LIST*/
#include<conio.h>
#include<iostream.h>
struct node
{
int data;
struct node *link;
};
void main()
{
struct node *ptr,*front=NULL,*rear=NULL,*temp;
int num;
char ch;
clrscr();
cout<<“Inserting elements in the Queue:”<<endl;
do
{
temp=new node;
cout<<“Enter the element to be inserted: “;
cin>>num;
temp->data=num;
temp->link=NULL;
if(front==NULL)
{
front=temp;
rear=temp;
}
else
{
rear->link=temp;
rear=temp;
}
cout<<“do you want to continue inserton?? “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
cout<<“Elements of queue are:”<<endl;
for(ptr=front;ptr!=NULL;ptr=ptr->link)
{
cout<<ptr->data<<“\t”;
}
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *