在C语言中为了减少时间和空间,对单链表采用就地逆置的方法,话不多说,完整代码如下。 #include<stdio.h>#include<malloc.h>#define LEN sizeof (struct Node)struct Node{int data;//定义数据域struct Node *next;//定义指针域int length;//记录顺序表的长度};//建立
单链表就地逆置算法C语言版 Status Contrary(LinkList L) LinkList p,q;p=L->next;L->next=NULL;while(p!=NULL){ q=p;p=p->next;q->next=L->next;L->next=q;} return OK;}