单链表反转

带头节点的单链表反转

void Reverse(list l)
  2 {
  3     if(l->next == NULL)     //空链表
  4         return;
  5     node *cur   = l->next;
  6     node *next  = cur->next;
  7     
  8     while(next)
  9     {
 10         node *tmp = next->next;
 11         next->next = cur;
 12         cur = next;
 13         next = tmp;
 14     }
 15     l->next->next = NULL;
 16     l->next = cur;
 17 }

你可能感兴趣的:(list,null)