单链表反转的递归方法

来源:互联网 发布:金蝶数据对接 编辑:程序博客网 时间:2024/04/29 02:00

node *reverse(node *head, node*pre)      //逆转单链表函数。这是笔试时需要写的最主要函数

{

      node *p=head->next;

      head->next = pre;

      if(p)

             return reverse(p, head);

      else

             return head;

}

 

int main(int argc,char* argv[])

{

      node *head = create(6);

      print(head);

      head = reverse(head, NULL);

      print(head);

      return getchar();

}