如何实现单链表逆置

来源:百度知道 编辑:UC知道 时间:2024/06/10 11:37:56

定义一个节点结构:
struct node
{
int date;//可能使用其它类型或结构
node *next;
};

假设你的链表已经存在,为L
node *curnode = L;//当前节点,指向开始
node *temp=curnode->next;//临时节点
curnode->next=NULL;
L=curnode;
//先将指针指向队尾
while(temp != NULL)
{
curnode=temp;
temp =curnode->next;
curnode->next=L;
L=curnode;
}