Hello, I am trying to create a singly linked list implementation of a stack, but I keep getting strange errors that have to do with my dequeue function, but I have no idea what I could be doing wrong, my compiler keeps pointing to the line "frontNode = frontNode->next;" but I can't figure out why.
//The nodes that make up the queue
//Constructs an empty queue
//Returns true if the queue is empty
//Returns the value at the front of the queue
//Adds a new value to the end of the queue
void enqueue(int newData);
//Deletes the data at the front of the queue
//Returns the current size of the queue
//Keeps track of the front of the queue
//Keeps track of the rear of the queue
Basically every time I try to run my main QueueTest program, the whole program breaks in a different place of the same while loop, never quite getting to the end. But whenever I comment out the call to the dequeue, it runs through fine (except for the stuff that I need the dequeue functional for). I'm pretty sure I'm getting some kind of segmentation fault but have no idea why.
If you call dequeue on an empty Queue, you're going to dereference a null pointer. Also, your destructor needs work -- front and rear will not always be the only nodes allocated, and if front == rear, you're going to be deleting the same node twice.