QUEUE ARRAY USING ADT
  
AIM:
To write a program to implement Queue using Array.

ALGORITHM:
1.INSERTION:
STEP 1:Create a function insert() with argument element to be added.
STEP 2:Assign the new element in the array by incrementing the REAR 
variable. 
2.DELETION:
STEP 1:Create a delete(),  store the deleted value in a variable .
STEP 2:Increment the FRONT variable by 1.

3.DISPLAY:
STEP 1:Create a function display(), print the values upto REAR by 
incrementing index value.

PROGRAM:
#include<iostream.h>
#include<stdlib.h> #include<conio.h>
#define size 5
class MyQ
{
private:
struct queue
{
int que[size]; int front,rear;
}Q;
public: MyQ();
int Qfull();
int insert(int); int Qempty();
int delet();
void display();
};
MyQ::MyQ()
{
Q.front=-1;
Q.rear=-1;
}
int MyQ::Qfull()
{
if(Q.rear>=size-1)
return 1;
else
return 0; } int MyQ::insert(int item) {
}
int MyQ::insert(int item)
{
if(Q.front==-1)
Q.front++;
Q.que[++Q.rear]=item;
return Q.rear;
}
int MyQ::Qempty()
{
if((Q.front==-1)||(Q.front>Q.rear))
return 1;
else
return 0;
}
int MyQ::delet()
{
int item;
item=Q.que[Q.front];
Q.front++;
cout<<"\n the deleted item is "<<item;
return Q.front;
}
void MyQ::display()
{
int i;
for(i=Q.front;i<=Q.rear;i++)
cout<<" "<<Q.que[i];
}
void main(void)
{
int choice,item;
char ans;
MyQ obj;
clrscr();
do
{
cout<<"\n Main Menu";
cout<<"\n 1.Insert\n 2. Delete\n 3.Display";
cout<<"\n Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:
if(obj.Qfull())
cout<<"\n cannot insert the element";
else
{
cout<<"\n Enter the number to be inserted";
cin>>item;
obj.insert(item);
}
break; case 2:
if(obj.Qempty())
cout<<"\n Queue underflow!!";
else
obj.delet();
break;
case 3:
if(obj.Qempty())
cout<<"\n Queue empty!!";
else
obj.display();
break;
default:
cout<<"\n wrong choice";
break;
}
cout<<"\n Do you want to continue?";
ans=getch();
}
while(ans=='Y'||ans=='y');
}

OUTPUT: 

Main Menu 

1.Insert 
2. Delete 
3.Display 
Enter your Choice: 1 
Enter the number to be inserted 10 
Do You Want to continue? y 
Enter your Choice: 1 
Enter the number to be inserted 20 
Do You Want to continue? y

Enter your Choice: 1
Enter the number to be inserted 30
Do You Want to contiue?y

Enter your Choice: 3
10 20 30
Do You Want to contiue?y

Enter your Choice: 2
The deleted item is  10
Do You Want to continue?y

Enter your Choice: 3
20 30
Do You Want to contiue?  N