将单向链表reverse,如ABCD变成DCBA,只能搜索链表一次。

来源:互联网 发布:js让div显示 编辑:程序博客网 时间:2024/06/08 10:50

一边遍历一边插入头部。

typedef struct linknode{int data;struct linknode *next;}node;//将一个链表逆置node *reverse(node *head){node *p,*q,*r;p=head;q=p->next;while(q!=NULL){r=q->next;q->next=p;p=q;q=r;}head->next=NULL;head=p;return head;}


原创粉丝点击