IMPLEMENT SEARCH IN SINGULAR QUEUE USING LINKED LIST

/*PROGRAM TO IMPLEMENT SEARCH 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,count=0,c=0;
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’);
cout<<“Elements of queue are:”<<endl;
for(ptr=front;ptr!=NULL;ptr=ptr->link)
{
cout<<ptr->data<<“\t”;
}
cout<<endl<<“Enter the element you want to search: “;
cin>>num;
for(ptr=front;ptr!=NULL;ptr=ptr->link)
{
if(ptr->data==num)
{
cout<<“Element found at “<<count+1<<” position”<<endl;
c++;
}
count++;
}
if(c==0)
cout<<“Element not found in the queue”<<endl;
else
cout<<“Element found “<<c<<” times in the list”;
getch();
}

Leave a Reply

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