Professional Documents
Culture Documents
1 Linear Queue Program
1 Linear Queue Program
In queue the elements enter into the queue at one side and
deleted from another end. The main operations performed in the queue are inserting and deleting.
Queue operations
#include<iostream.h>
#include<conio.h>
template<class T>
class queue
T arr[50];
int rear,front;
public:
queue():rear(-1),front(-1)
void insert(T n)
if(rear>=50)
cout<<”Overflow”;
else
rear=rear+1;
arr[rear]=n;
if(front==-1)
front=0;
}
T del()
if(front<0)
cout<<”Underflow”;
return 0;
else
T temp;
temp=arr[front];
if(front==rear)
front=rear=-1;
else
front=front+1;
return temp;
};
void main()
int j,ch,ch1,ch2;
char k;
float g;
clrscr();
queue<int>oi;
queue<char>oc;
queue<float>of;
cout<<”Enter the type of data\n 1. Int\n 2. Char\n 3. Float\n Enter your choice:”;
cin>>ch;
clrscr();
do
switch(ch)
cin>>ch1;
switch(ch1)
cin>>j;
oi.insert(j);
break;
case 2:
j=oi.del();
cout<<endl<<”Element:”<<j;
getch();
break;
}
clrscr();
break;
cin>>ch1;
switch(ch1)
cin>>k;
oc.insert(k);
break;
case 2:
k=oc.del();
cout<<endl<<”Element:<<k”;
getch();
break;
clrscr();
break;
cin>>ch1;
switch(ch1)
cin>>g;
of.insert(g);
break;
case 2:
g=of.del();
cout<<endl<<”Element:<<g”;
getch();
break;
clrscr();
break;
cin>>ch2;
while(ch2==1);
getch();
1. Int
2. Char
3. Float
1. Insert
2. Delete
1. Yes
2. No
No