struct node
{
int data;
node* next;
};
// 单向链表头,如何倒序操作
inverse(node* head)
{
node thead;
thead.next = NULL;
for(current = head; current!=null; )
{
if ( current == head )
{
node * t = current->next;
thead.next = current;
current->next = NULL;
current = t;
}
else
{
node * t = current->next;
node* t2 = thead.next;
thead.next = current;
current->next = t2;
current = t;
}
}
return thead.next;
}
{
int data;
node* next;
};
// 单向链表头,如何倒序操作
inverse(node* head)
{
node thead;
thead.next = NULL;
for(current = head; current!=null; )
{
if ( current == head )
{
node * t = current->next;
thead.next = current;
current->next = NULL;
current = t;
}
else
{
node * t = current->next;
node* t2 = thead.next;
thead.next = current;
current->next = t2;
current = t;
}
}
return thead.next;
}
本文介绍了一种实现单向链表倒序的方法。通过一个循环结构,不断调整当前节点的指向,最终达到整个链表倒序的效果。该算法简单易懂,适合初学者学习。
1569

被折叠的 条评论
为什么被折叠?



