将一个单链表逆序struct test{int number;double score;test* next;}void reverse(test*& head){test* pe = head;test* ps = head->next;while(ps = NULL){pe->next = ps->next;ps->next = head;head = ps;ps = pe->next;}}

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/29 03:17:12
将一个单链表逆序structtest{intnumber;doublescore;test*next;}voidreverse(test*&head){test*pe=head;test*ps=hea

将一个单链表逆序struct test{int number;double score;test* next;}void reverse(test*& head){test* pe = head;test* ps = head->next;while(ps = NULL){pe->next = ps->next;ps->next = head;head = ps;ps = pe->next;}}
将一个单链表逆序
struct test
{
int number;
double score;
test* next;
}
void reverse(test*& head)
{
test* pe = head;
test* ps = head->next;
while(ps = NULL)
{
pe->next = ps->next;
ps->next = head;
head = ps;
ps = pe->next;
}
}

将一个单链表逆序struct test{int number;double score;test* next;}void reverse(test*& head){test* pe = head;test* ps = head->next;while(ps = NULL){pe->next = ps->next;ps->next = head;head = ps;ps = pe->next;}}
数据结构就不用讲了吧...
下面的函数体是这样:
pe指向链表头
ps指向链表头的下一个节点
原链表头的下一结点不空时{
原链表头的下一节点 指向 ps的下一结点
ps的下一结点指向现链表头
链表头指向ps
ps指向原链表头的下一结点
}
循环中的四步完成了把原链表头的下一个节点移到链表头的动作,重复到原链表头为链表尾为止.这样就完成了链表的倒序