/*PROGRAM TO IMPLEMENT SEARCH OPERATION IN CIRCULAR 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,c=0,count=0;
char ch;
clrscr();
cout<<“Inserting elements in the list:”<<endl;
do
{
temp=new node;
cout<<“Enter the element to be inserted: “;
cin>>num;
temp->data=num;
if(front==NULL)
{
front=temp;
rear=temp;
temp->link=front;
}
else
{
rear->link=temp;
rear=temp;
temp->link=front;
}
cout<<“Do you want to continue inserton?? “;
cin>>ch;
}while(ch==’y’);
cout<<“Elements of queue are:”<<endl;
cout<<front->data<<“\t”;
for(ptr=front->link;ptr!=front;ptr=ptr->link)
{
cout<<ptr->data<<“\t”;
}
cout<<endl<<“Enter the element you want to search: “;
cin>>num;
if(front->data==num)
{
c++;
cout<<“Element is found at 1 position”;
}
count=1;
for(ptr=front->link;ptr!=front;ptr=ptr->link)
{
count++;
if(ptr->data==num)
{
c++;
cout<<“Element found at “<<count<<” position”<<endl;
}
}
if(c==0)
cout<<“!!Element is not found!!”<<endl;
else
cout<<“Element found “<<c<<” times in the queue”;
getch();
}