#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#define MAX 5
void main()
{
int i,a[MAX],rear=-1,front=-1,n,num,count=0;
char ch;
clrscr();
do
{
if(rear>=MAX-1)
{
cout<<"Queue is
full"<<endl;
break;
}
else
{
rear++;
cout<<"Enter the number to be
inserted: ";
cin>>n;
a[rear]=n;
}
cout<<"Do you want to insert more
numbers(y/n):- ";
cin>>ch;
}while(ch=='y'||ch=='Y');
cout<<"Elements of queue are:
"<<endl;
for(i=0;i<=rear;i++)
{
cout<<a[i]<<"\t";
}
cout<<endl<<"Enter the
element to be searched:- ";
cin>>n;
for(i=front;i<=rear;i++)
{
if(n==a[i])
{
cout<<"Element found
at"<<i+1<<" position"<<endl;
count++;
}
}
if(count==0)
cout<<"Element is not present in
the queue";
getch();
}
No comments:
Post a Comment