Note that there are some explanatory texts on larger screens.

plurals
  1. POLinkedList/Stack/Queue - Help with Dequeuing
    primarykey
    data
    text
    <p>I had to write a linked list, then turn it into a dynamic Stack, then turn that into a dynamic Queue. Well everything seems to work except the "dequeuing", right as the programs about to finish, it gives me an error: "An unhandled win32 exception occured in LinkedList_Stack_BNS11.exe [4972].". </p> <p>I'm only assuming it's the dequeuing, because as I step through and/or run the program, it runs smoothly up till that part, so maybe I sent one of the pointers wrong or something?</p> <p><strong>Output:</strong></p> <p>Enquing 5 items.... // Finsihes</p> <p>The values in the queue were (Dequeuing):</p> <p>0</p> <p>1</p> <p>2</p> <p>// Correct number in que but...</p> <p>//Program gives that error right here. When it should finish and close.</p> <p>If I included too much code let me know and I'll chop it down to just the "Dequeuing" (Which is in the very middle of all the stuff below)</p> <p>Thanks in advance for the help!! I'm just not seeing what I did wrong. Thinking it maybe has something to do with where "head" is pointing? Idk.</p> <p><strong>Header File:</strong></p> <pre><code>class NumberList { private: // struct ListNode { int value; // Value in this node struct ListNode *next; // Pointer to the next node }; ListNode *head; // List head pointer ListNode *rear; public: //Constructor NumberList() { head = NULL; rear = NULL; } //Destructor ~NumberList(); //Stack operations bool isEmpty(); //Queue operations void enqueue(int); void dequeue(int &amp;); }; #endif </code></pre> <p><strong>List_Stack_Queue.cpp:</strong></p> <pre><code>bool NumberList::isEmpty() { bool status; if(!head) status = true; else status = false; return status; } void NumberList::enqueue(int num) { ListNode *newNode; // Point to a new node // Allocate a new node and store num there. newNode = new ListNode; newNode-&gt;value = num; //If there are no nodes in the list // make newNode the first node. if(isEmpty()) { head = newNode; rear = head; //newNode-&gt;next = NULL; } else { rear-&gt;next = newNode; rear = rear-&gt;next; //newNode-&gt;next = head; //head = newNode; } } void NumberList::dequeue(int &amp;num) { ListNode *temp; if(isEmpty()) cout &lt;&lt; "The queue is empty.\n"; else { num = head-&gt;value; temp = head; head = head-&gt;next; delete temp; } } </code></pre> <p><strong>MAIN:</strong></p> <pre><code>const int MAX_VALUES = 3; // Create a DynIntQueue object. NumberList iQueue; // Enqueue a series of numbers. cout &lt;&lt; "Enqueuing " &lt;&lt; MAX_VALUES &lt;&lt; " items...\n"; for (int x = 0; x &lt; MAX_VALUES; x++) iQueue.enqueue(x); cout &lt;&lt; endl; //Dequeue and retrieve all numbers in the queue cout &lt;&lt; "The values in the queue were (Dequeuing):\n"; while(!iQueue.isEmpty()) { int value; iQueue.dequeue(value); cout &lt;&lt; value &lt;&lt; endl; } return 0; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload