title: C using while loop with linked list
body: <p>I have come to a problem where I try to use while loop on linked list.
  I have two linked lists, namely <code>temp</code> and <code>graph</code>. I am using a while loop to do tasks <code>while(temp != NULL)</code>. To move on in each of the loop, I am assigning <code>temp = temp-&gt;link</code>. However, this code does not compile. I realize that recursive function could be a solution, but the function is actually way more complicated that I don't think recursive would be such a good idea. By the way, <code>graph</code> is already a built linked list. Thanks in advance!</p>
  
  <p>P.S. It is part of homework.</p>
  
  <pre><code>temp = graph-&gt;link;
  while(temp!=NULL){
      if(stack-&gt;link == NULL){
          stack-&gt;link = (node_pointer)malloc(sizeof(graph));
          stack-&gt;link-&gt;weight = temp-&gt;weight;
          stack-&gt;link-&gt;vertex = temp-&gt;vertex;
      }
      temp = temp-&gt;link; //Here is the problem.
  }
  </code></pre>
  
  <p>edit:</p>
  
  <p>stack and graph are both arrays of linked list:</p>
  
  <pre><code>typedef struct node *node_pointer;
  
  struct node{
      int vertex;
      int weight;
      int visited;
      struct node *link;
  };
  node_pointer graph[50];
  node_pointer stack[50];
  node_pointer temp;
  </code></pre>