title: insert new node at any index within a single linked list
body: <p>how would i go about creating a function that will allow me to insert a new node at any index within a linked list? here's the struct:</p>
  
  <pre><code>struct node {
      int data;
      struct node* next;
  };
  </code></pre>
  
  <p>here's the function, note there's only a double pointer, index, and data parameter.</p>
  
  <pre><code>void insertN(struct node** headRef, int index, int data);
  </code></pre>
  
  <p>and here's what the result should look like after calling insertN:</p>
  
  <pre><code>[ HEAD ] -&gt; [ 0 ] -&gt; [ 15 ] -&gt; [ 10 ] -&gt; [ 5 ] -&gt; [ NULL ]
  insertN( &amp;head, 3, -44);
  [ HEAD ] -&gt; [ 0 ] -&gt; [ 15 ] -&gt; [ 10 ] -&gt; [ -44 ] -&gt; [ 5 ] -&gt; [ NULL ]
  insertN( &amp;head, 4, -55);
  [ HEAD ] -&gt; [ 0 ] -&gt; [ 15 ] -&gt; [ 10 ] -&gt; [ -44 ] -&gt; [-55 ] -&gt; [ 5 ] -&gt; [ NULL ]
  insertN( &amp;head, 0, -66);
  [ HEAD ] -&gt; [ -66 ] -&gt; [ 0 ] -&gt; [ 15 ] -&gt; [ 10 ] -&gt; [ 5 ] -&gt; [ NULL ]
  </code></pre>
  
  <p>i know how to add a new node to the head, but not at any point. the way i was thinking was </p>
  
  <pre><code>void insertN(struct node** headRef, int index, int data) {
      struct node* new;
      int i;
      for (i = 0; i &lt;= index; i++) {
          if (i == index) {
              /* move what was here to next node and put in new node */
          }
      }
  
      return;
  }
  </code></pre>
  
  <p>i just am unsure how to go about doing all this, because if something was in the node, i have to move all subsequent nodes as well.</p>