链表逆序

来源:互联网 发布:淘宝买电子版资料 编辑:程序博客网 时间:2024/06/07 15:56
<pre name="code" class="cpp">struct Node{int data ;Node *next ;};typedef struct Node Node ;


Node * ReverseList(Node *head) //链表逆序{if (head == NULL || head->next == NULL)return head;Node *p1 = head;Node *p2 = p1->next;Node *p3 = p2->next;p1->next = NULL;while (p3 != NULL){p2->next = p1;p1 = p2;p2 = p3;p3 = p3->next;}p2->next = p1;head = p2;return head;}

0 0
原创粉丝点击