title: Sequence insert at arbitrary index implemented with Linked list
body: <p>I'm trying to implement sequence_insert_at using the add_to_front function <a href="http://ideone.com/cCWsF9" rel="nofollow">here</a></p>
  
  <p>Everything before</p>
  
  <pre><code>typedef struct sequence *Sequence;
  </code></pre>
  
  <p>is pasted from another c file. </p>
  
  <pre><code>void sequence_insert_at(Sequence s, int pos, int item)
  {
      struct node* temp = s-&gt;lst;
      for(; pos &gt; 0; --pos)
      {
          temp = temp-&gt;rest;
      }
      add_to_front(&amp;temp, item);
      ++s-&gt;length;
      if(!temp-&gt;rest)
      {
          s-&gt;end = temp;
      }
      //s-&gt;lst = temp;
  }
  </code></pre>
  
  <p>I don't know why I keep getting a runtime error. if I clone s->lst and traverse the clone, I'm not modifying the pointer to the node in s, but if I change temp, s->lst should have the reflected changes since the nodes are all linked still. Any ideas as to how to fix this? I tried creating another node that is one before the temp after traversal, and then setting it->rest = temp, but that failed as well.</p>