#include "conio.h"
#include "process.h"
int ins(int[], int);
int del(int[]);
void display(int[], int, int);
const int size=20;
int q[size], f=-1, r=-1;
int main()
{
int item, res;
char ch='y';
clrscr();
while(ch=='y' ||ch=='Y')
{
cout<<"\nEnter Item for insertion: ";
cin>>item;
res=ins(q,item);
if (res==-1)
{
cout<<"\nOver flow\n ";
exit(1);
}
cout<<"\nQueue: ";
display(q, f, r);
cout <<"\nInsert more Y/N :- ";
ch=getch();
}
cout << "\n\nDeletion of element begins... \n";
ch='y';
while (ch=='y'||ch=='Y')
{
res=del(q);
if(res==-1)
{
cout<< "\nUnder flow";
exit(1);
}
else
{
cout<<"\nElement deleted is : "<
display(q, f, r);
}
cout<<"\nWant to delete more element Y/N -";
cin >> ch;
if(ch=='n'||ch=='N')
cout<<"\nQueue: ";
display(q,f,r);
}
getch();
return 0;
}
int ins(int q[], int ele)
{
if (r==size-1)
return -1;
else if (r==-1)
{
f=r=0;
q[r]=ele;
}
else
{
r++;
q[r]=ele;
}
return 0;
}
int del (int q[])
{
int ret;
if(f==-1)
return -1;
else
{
ret = q[f];
if (f==r)
f=r=-1;
else
f++;
}
return ret;
}
void display(int q[], int f, int r)
{
if (f== -1) return;
cout<< "F-";
for(int i = f;i<=r;i++)
cout< cout<<"R";
}
/* Output::::::::::::::::::::
Enter Item for insertion: 10
Queue: F-10-R
Insert more Y/N :-
Enter Item for insertion: 20
Queue: F-10-20-R
Insert more Y/N :-
Enter Item for insertion: 30
Queue: F-10-20-30-R
Insert more Y/N :-
Deletion of element begins...
Element deleted is : 10
Queue: F-20-30-R
Want to delete more element Y/N -
*/
No comments:
Post a Comment