title: How do "inner" and "outer" work in this bubble sort code?
body: <p>I am trying to learn the bubble sort algorithm in a book for C. I can't seem to understand in the code below how <code>int outer</code> and <code>int inner</code> link to which element of the <code>nums</code> array. Like how does <code>inner</code> become <code>nums[0]</code> while <code>outer</code> becomes <code>nums[1]</code> (if I'm correct), then progresses through the loop?</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  int main()
  {
      int ctr, inner, outer, didSwap, temp;
      int nums[10];
      time_t t;
  
      srand(time(&amp;t));
  
      for (ctr = 0; ctr &lt; 10; ctr++)
      {
          nums[ctr] = (rand() % 99) + 1;
      }
  
      puts(&quot;\n Here is the list before the sort: &quot;);
      for (ctr = 0; ctr &lt; 10; ctr++)
      {
          printf(&quot;%i\n&quot;, nums[ctr]);
      }
  
      for (outer = 0; outer &lt; 9; outer++)
      {
          didSwap = 0;
          for (inner = outer; inner &lt; 10; inner++)
          {
              if (nums[inner] &lt; nums[outer])
              {
                  temp = nums[inner];
                  nums[inner] = nums[outer];
                  nums[outer] = temp;
                  didSwap = 1;
              }
          }
          if (didSwap == 0)
          {
              break;
          }
      }
  
      puts(&quot;\n Here is the list after the sort: &quot;);
      for ( ctr = 0; ctr &lt; 10; ctr++)
      {
          printf(&quot;%i\n&quot;, nums[ctr]);
      }
  
      return 0;
  }
  </code></pre>