Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not entirely sure I understand what you're trying to do, but if I;m guessing right you're trying to 'pop' the 1st element of the array (<code>items[0]</code>) into the <code>nPopFront</code> int reference, then move all the subsequent elements of the array over by one so that the 1st element is replaced by the 2nd, the 2nd by the 3rd, and so on. After this operation, the array will contain one less total number of elements.</p> <p>Not having the full declaration of the <code>quack</code> class makes most of the following guesswork, but here goes:</p> <p>I'm assuming that <code>item[0]</code> represents the 'front' of your array (so it's the element you want 'popped').</p> <p>I'm also assuming that 'count` is the number of valid elements (so item[count-1] is the last valid element, or the 'back' of the array).</p> <p>Given these assumptions, I'm honestly not sure what <code>top</code> is supposed to represent (so I might be entirely wrong on these guesses).</p> <p>Problem #1: your <code>nPopFront</code> assignment is reversed, it should be:</p> <pre><code>nPopFront = items[0].n; </code></pre> <p>Problem #2; your <code>for</code> loop is a big no-op. It walks through the array assigning elements back to their original location. I think you want it to look more like:</p> <pre><code>for (int i = 1; i &lt; count; ++i) { items[i-1].n = items[i].n; // move elements from back to front } </code></pre> <p>Finally, you'll want to adjust <code>count</code> (and probably <code>top</code> - if you need it at all) before you return to adjust the new number of elements in the data structure. The whole thing might look like:</p> <pre><code>bool quack::popFront(int&amp; nPopFront) { if ( count &gt;= maxSize ) return false; if ( count == 0 ) return false; // nothing to pop nPopFront = items[0].n; intFrontPtr = &amp;items[0].n; // do we really need to maintain these pointers? intBackPtr = &amp;items[count-1].n; for (int i = 1; i &lt; count; ++i) { items[i-1].n = items[i].n; // move elements from back to front } count -= 1; // one less item in the array return true; } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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