单链表的逆转 C语言

来源:互联网 发布:html源码大全 编辑:程序博客网 时间:2024/06/16 01:04
#include<stdio.h>#include<stdlib.h>typedef struct node{int data;struct node *next;}node;node * reverse(node * head){node *p1,*p2,*p3;if(head==NULL||head->next==NULL)return head;p1=head;p2=p1->next;while(p2){p3=p2->next;p2->next=p1;p1=p2;p2=p3;}head->next=NULL;head=p1;return head;}void main(){node a[4]={{1,NULL},{2,NULL},{3,NULL},{4,NULL}};a[0].next=&a[1];a[1].next=&a[2];a[2].next=&a[3];reverse(&a[0]);getchar();}


 

原创粉丝点击