title: Resetting linked list ordinals
body: <p>So I'm playing around with linked lists, trying to get my brain around them, and I decided to add "ordinal" values to each node in my list.  This way, I can delete by ordinal rather than value, and do some other cool stuff later on.  </p>
  
  <p>Only, when I delete an element from the list all the ordinals get thrown out of whack (fairly obvious, that), so I thought "ok, I'll just run up the list in a different function, resetting all of the ordinals".  I could technically start this function at the element that got deleted and pass it in the ordinal from that node to save time, as the previous nodes should be untouched, but for now I'm doing it the less elegant way because I said so.</p>
  
  <p>"What is your question?".  I knew you'd ask that!  "Get on with it!"  I knew you'd say that!</p>
  
  <p>The test program, which I can link to or include here, just creates a list of 5 nodes, removes the 3rd node and then adds a node onto the end.</p>
  
  <p>The expected output is: <code>DEBUG: resetting ordinals: 0 1 2 3 4</code></p>
  
  <p>The actual output is: <code>DEBUG: resetting ordinals: 1 2 4 5 5</code></p>
  
  <p>So, without any further ado, here is my question: Why is the actual output different from my expectations?</p>
  
  <pre><code>void ll_fix(node_t* list)
  {
    node_t* root = list;
    int ordinal = 0;
    printf("DEBUG: resetting ordinals: ");
    while(list-&gt;next != NULL)
    {
      list-&gt;ordinal = ordinal;
      list = (node_t*)list-&gt;next;
      printf("%d ",list-&gt;ordinal);
      ordinal++;
    }
    printf("%d\n",list-&gt;ordinal);
    list = root; // rewind the list
  }
  </code></pre>