Hey guys. I am trying to take a normal queue and change it into a cyclic queue, which basically means that the enqueue operation will make the elements shift to make space if the rear pointer is pointing at the end of the queue.
I am getting an error about a "Missing External Link," but I also am not too sure if I am implementing the class correctly as this is my first program using OOP. If you guys have any suggestions that would be awesome. Thanks :)
Also, if you guys could let me know how to add line numbers to my code that would be huge, as I'm sure its annoying to try and help without them.
#include <iostream>
using namespace std;
class CirQueue
{
private:
int queue_size;
int n;
protected:
int *buffer;
int front;
int rear;
public:
CirQueue(void)
{
front=0;
rear=0;
queue_size=10;
buffer= new int[queue_size];
}
CirQueue (int n)
{
front=0;
rear=0;
queue_size=n;
buffer=new int[queue_size];
}
~CirQueue(void)
{
delete buffer;
buffer= NULL;
}
void enqueue(int v)
{
if (rear<queue_size)
buffer[rear++]=v;
else if(rear==n)
if(front>0)
rear=0;
else
if(compact())
buffer[rear++]=v;
}
int dequeue(void)
{
if(front<rear)
return buffer[front++];
else
{
return -1;
}
}
private:
bool compact(void);
};
void main()
{
CirQueue Q1(5);
Q1.enqueue(2);
Q1.enqueue(8);
int x = Q1.dequeue();
int y = Q1.dequeue();
}