I am trying to create a queue class and then allow the user to input integers at the back of the queue and take them from the front. This is what I have so far, it runs but will not output the size of the queue correctly. Any help would be much appreciated.
# include <iostream>
# include <conio.h>
# include <cstdlib>
using namespace std;
class queue
{
int a[100];
int front;
int rear;
public:
queue();
~queue();
void push(int i);
int pop();
int isempty();
int isfull();
int holds();
};
queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
delete []a;
}
void queue::push(int i)
{
if(isfull())
{
cout<<"******Queue is FULL !!!No pushion allowed further.******";
return;
}
a[rear] = i;
rear++;
}
int queue::pop()
{
if(isempty())
{
cout<<"******Queue Empty !!!Value returned will be garbage.******";
return (-9999);
}
return(a[front++]);
}
int queue::isempty()
{
if(front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if(rear == 100)
return 1;
else
return 0;
}
int queue::holds()
{
return front;
}
int main() {
queue a;
int str;
int choice;
do {
cout << "Queue holds " << a.holds() << " strings\n";
cout << "(0) Push, (1) Pop, (2) Exit : ";
cin >> choice;
if (choice == 0) {
cout << "Input string: ";
cin >> str;
a.push(str);
} else if (choice == 1) {
cout << a.holds() << " : " << a.pop() << "\n";
}
} while (choice != 2);
return 0;
}