写一算法:借助于栈将一个单链表逆置

链表和栈要自己写代码定义
2025-02-28 14:37:15
推荐回答(3个)
回答1:

#include
#include

typedef struct _LinkList
{
struct _LinkList *next;
} LinkList;

LinkList* ReverseList_L(LinkList *head)
{
LinkList *prior, *cur, *next, *temp;

prior = NULL;
cur = head;
next = head->next;

while (next != NULL)
{
cur->next = prior;
temp = next->next;
next->next = cur;
prior = cur;
cur = next;
next = temp;
}

return cur;
}

int main(void)
{
LinkList n1, n2, n3, n4;
n1.next = &n2;
n2.next = &n3;
n3.next = &n4;
n4.next = NULL;
ReverseList_L(&n1);

return 0;
}

为什么最近这么多人问这个?难道都是一个学校的?

回答2:

http://www.cnblogs.com/aceofspades/archive/2008/10/05/1304056.html

回答3:

链表和栈给出来了么,还是要自己写代码定义