title: sort a singly linked list formed of 1, 2 and 0s by swapping the nodes through one traversal in C
body: <p>I'm trying to solve the question that I need to sort a given linked list which values consist of 1, 2 and 0 by traversing the list only once and I need to swap the nodes not values.
  my code is:</p>
  <pre><code>    #define max 3
  
  void sortList(node **headRef)
  {
      if(*headRef==NULL){
          return;
      }
      node* head[max];
      node*tail[max];
      node* curr=*headRef;
      int i;
      for(i=0; i&lt;max; i++){
          head[i]=tail[i]=NULL;
      }
      while(curr!=NULL){
          i=curr-&gt;data;
          if(head[i]==NULL){
              head[i]=tail[i]=curr;
          }
          else{
              tail[i]=tail[i]-&gt;next=curr;
          }
          curr=curr-&gt;next;
      }
      for(int i=0, curr=(*headRef)=NULL; i&lt;max; i++){
          if(head[i]!=NULL){
              if(*headRef==NULL){
                  *headRef=head[i];
              }
              else{
                  curr = curr-&gt;next =head[i];
              }
              curr=tail[i];
          }
          
      }
      curr-&gt;next=NULL;
  }
  </code></pre>
  <p>but it keep giving me an error and I don't know how to solve it if anyone can help me please.</p>