Code:
/* Circular Queues */
#include<iostream.h>
#include<conio.h>
#include <stdlib.h>
#include <string.h>
const int MAX = 5;
class cqueue
{
int a[MAX],front,rear;
public :
cqueue()
{
front=rear=-1;
}
void insert(char); // THIS IS THE PROBLEM, I changed int to char
int deletion();
void display();
};
void cqueue :: insert(char TaxLic) // related
{
if((front==0 && rear==MAX-1) || (rear+1==front))
cout<<" Circular Queue is Full";
else
{
if(rear==MAX-1)
rear=0;
else
rear++;
a[rear]=TaxLic; //related
}
if(front==-1)
front=0;
}
int cqueue :: deletion()
{
int k;
if(front==-1)
cout<<"Circular Queue is Empty";
else
{
k=a[front];
if(front==rear)
front=rear=-1;
else
{
if(front==MAX-1)
front=0;
else
front++;
}
}
return k;
}
void cqueue :: display()
{
int i;
if(front==-1)
cout<<"Circular Queue is Empty";
else
{
if(rear < front)
{
for(i=front;i<=MAX-1;i++)
cout<<a[i]<<" ";
for(i=0;i<=rear;i++)
cout<<a[i]<<" ";
}
else
{
for(i=front;i<=rear;i++)
cout<<a[i]<<" ";
cout<<endl;
}
}
}
int main()
{
cqueue c1;
char TaxLic [7];
char Dname [20];
char TaxTyp [15];
int ch,val;
char op;
do
{
//clrscr();
system("cls");
cout<<"-----------Menu-------------\n";
cout<<"1.Insertion\n";
cout<<"2.Deletion\n";
cout<<"3.Display\n";
cout<<"4.Exit\n";
cout<<"Enter Your Choice <1..4> ?";
cin>>ch;
switch(ch)
{
case 1 : cout<<"Enter Taxi License Number: ";
fflush(stdin);
gets(TaxLic);
//cin>>val;
c1.insert(TaxLic); // can't insert because of char type
break;
case 2 : val=c1.deletion();
cout<<"Deleted Element :"<<val<<endl;
break;
case 3 : c1.display();
break;
}
cout<<"Do you want to continue<Y/N> ?";
fflush(stdin);
cin>>op;
}while(op=='Y' || op=='y');
getch();
}
I put a sign in it.. The coding is working but when i tried to change the date tyoe from int (TaxType) to char, it's not working..