Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a queue - removing the same value twice issue C++
    primarykey
    data
    text
    <p>I have to create a queue class from a data file, it's basically a two column .dat file with a character in the first column and a corresponding number in the second column. In this program there are two queues, high priority and low priority. </p> <p>The * asterisk and associated number denotes how many times to remove them from the queue, alternating between removing from the high queue and the low queue.</p> <p>I can populate the queue without issue (high priority only goes to high etc) -- but when I remove characters from the queue it will remove characters from a queue it shouldn't have access to. </p> <p>Snippet of main.cpp:</p> <pre><code> //This is the main.cpp where characters are sent into the queue. if (number1 == 1 &amp;&amp; character != '*') //if number is 1, sends to high priority queue { myHigh.addToQueue(character); } else if (number1 == 2 || number1 == 3 ||number1 == 4 || number1 == 5 &amp;&amp; character != '*') { myLow.addToQueue(character); } for (int i=1; i&lt;=number1; i++) { if (character == '*') { myHigh.takeAway(); myLow.takeAway(); number1/=i; i=1; } } </code></pre> <p>Snippet of the arrayQueue class:</p> <pre><code>//this is in the arrayQueue class, it should remove values from the queue int arrayQueue::takeAway() { char letter; if (empty()) return -1; else { letter = queueArray[remove]; remove = (remove+1)%maxSize; count--; size--; cout &lt;&lt; letter &lt;&lt; " has been serviced and removed from the queue" &lt;&lt; endl; return letter; } } </code></pre> <p>Now, this works all fine if you just use myHigh.takeAway(); - the values get removed normally. However, if you use myLow.takeAway(); -- even without the myHigh.takeAway() it removes values that should only be in the high priority queue.</p> <p>Here is a portion of the output running ONLY the myLow.takeAway(), W is in the HIGH priority queue yet when running myLow.takeAway() it gets removed?</p> <pre><code>//OUTPUT R has been added to the queue and is assigned number 1 T has been added to the queue and is assigned number 2 W has been added to the queue and is assigned number 1 A has been added to the queue and is assigned number 3 W has been serviced and removed from the queue T has been serviced and removed from the queue </code></pre> <p>I hope I included enough to give anyone an idea of what's going on, any help at all is greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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