I'm having a little trouble with my enqueue and dequeue for a linked list implemented queue using c++. My teacher says templates are off limits and I cannot change the public and private functions, as he gave them to us. I keep getting a segmentation fault. I don't really understand what I am doing wrong. I've included the header and the enqueue and dequeue functions as well.
Header
const int MAX_STRING = 6;
typedef char Element300[MAX_STRING + 1];
class Queue300
{
public:
Queue300();
Queue300(Queue300&);
~Queue300();
void enQueue300(const Element300);
void deQueue300(Element300);
void view300();
private:
struct Node300;
typedef Node300 * NodePtr300;
struct Node300
{
Element300 element;
NodePtr300 next;
};
NodePtr300 front, rear;
};
EnQueue
void Queue300::enQueue300(const Element300 input)
{
NodePtr300 temp = NULL;
temp = new (std::nothrow) Node300;
if (temp == NULL)
{
cerr << "The queue is full, could not add(enqueue) any more elements." << endl;
}
else if (front == NULL && rear == NULL)
{
strcpy(temp->element, input);
rear = temp;
rear->next = NULL;
front = rear;
temp = NULL;
}
else
{
strcpy(temp->element, input);
temp = rear->next;
rear = temp;
rear->next = NULL;
temp = NULL;
}
}
Dequeue
void Queue300::deQueue300(Element300 input)
{
NodePtr300 temp = NULL;
if (rear == NULL && front == NULL)
{
cerr << "The queue is already empty, could not delete(dequeue) any more elements." << endl;
}
else if (front == rear)
{
strcpy(temp->element, input);
temp = front;
delete temp;
temp = NULL;
front = NULL;
rear = NULL;
}
else
{
strcpy(temp->element, input);
temp = front;
front = front->next;
temp->next = NULL;
delete temp;
temp = NULL;
}
}