title: Sort by integer leaves out last element of array C++
body: <p>I am new to C++ and I'm making a sorting algorithm to sort a list of structs by a certain integer value (ID in this very case); The sorting mechanism works just fine but leaves out the last element of the array in it's place and I really don't understand why. The list is in this order (130, 121, 140, 170, 120, 133) and this is the code:</p>
  <p>'''</p>
  <pre><code>class List{
      private:
          Step* head;
          Aisle* first;
          int size...
  </code></pre>
  <p>...</p>
  <pre><code>struct Step{
      Articolo info;
      Step* next;
      Step(Articolo to_push){this-&gt;info=to_push; this-&gt;next=NULL;};
  };
  
  struct Articolo{
      int ID;
      string name;
      int quantity;
      int aisle;
      float price;
  };
  
  void List::printCode(){
      Articolo temp_list[this-&gt;size];
      Step* temp = this-&gt;head;
      for (int i = 0; i &lt; this-&gt;size; i++){           // this whole part is to copy my dinamic list in an array, making it easier to re-arrange;
          temp_list[i] = temp-&gt;info;
          temp = temp-&gt;next;
      }
      Articolo lowest = temp_list[0];                 // i set the lowest element as the first element
      for (int j=1; j &lt; (this-&gt;size); j++){           // and start the sorting from the second element 
          if (lowest.ID &gt; temp_list[j].ID){
              lowest = temp_list[j];
              for (int k = j; k &gt; 0; k--){            // this is the sorting part
                  temp_list[k] = temp_list[k-1];
              }
              temp_list[0] = lowest;
          }
      }
      for (int z = 0; z &lt; this-&gt;size; z++){
          printInfo(temp_list[z]);                    // it's just a function for printing the info of an Article type variable;
      }
  }
  </code></pre>
  <p>'''</p>
  <p>And this is the output:</p>
  <pre><code>Codice: -1173245000; Nome: ���`����k�`������������ats����`���; Quantità: -1173245088; Corsia: 32759; Prezzo -0.0005558
  Codice: 120; Nome: Pringles; Quantità: 250; Corsia: 3; Prezzo 2.49
  Codice: 121; Nome: Kinder Bueno; Quantità: 1000; Corsia: 1; Prezzo 1.79
  Codice: 130; Nome: Twinkies; Quantità: 1300; Corsia: 1; Prezzo 1.49
  Codice: 140; Nome: Mars; Quantità: 3000; Corsia: 1; Prezzo 2.79
  Codice: 170; Nome: Pasta; Quantità: 150; Corsia: 2; Prezzo 0.79
  </code></pre>