title: How to traverse through n elements in a doubly linked list in C?
body: <p>As the title suggests, I have to iterate through a doubly linked list.  The only problem is that I have to iterate through "n" elements.</p>
  
  <p>For example, if I'm given a list of, 1 3 2 2 1 1, I have to iterate left or right depending on the value I'm on so: </p>
  
  <p>1 -> 3 -> 1 -> 1.  I can move over the same value as the value in the list.  Since I start at 1, I can move left or right 1 element (can only go right).  When I land on 3 I can move left or right 3 elements etc.</p>
  
  <pre><code>while (temp-&gt;next != NULL) {
     //traverse n elements left or right
  }
  </code></pre>
  
  <p>If I always just had to traverse 1 elements at a time it's as easy as</p>
  
  <pre><code>temp = temp-&gt;next;
  </code></pre>
  
  <p>If someone could explain a strategy to traversing 'n' elements depending on the value of the node, that would be much appreciated.</p>
  
  <p>edit: You can only go in the direction if there are enough elements in that direction.  So in the case of 1 -> 3, you can only go 3 to the right after.</p>