将链表的结构逆序、将链表以逆序的形式输出

来源:互联网 发布:犀牛5.0破解软件 编辑:程序博客网 时间:2024/05/22 07:52

1.将链表逆序:

List Traverse_List(List head)  //链表的逆序(结构上逆序){ListNode *cur=head;//cur表示当前节点ListNode *pre=NULL;//pre表示当前节点的直接前驱节点ListNode *traverse_head;//逆序后的头结点while(cur->next!=NULL){ListNode *temp=cur->next;cur->next=pre;pre=cur;cur=temp;}cur->next=pre;traverse_head=cur;return traverse_head;}

2.链表以逆序的形式输出

void Traverse_Print(List head)//链表以逆序的形式输出{if(head==NULL)return ;Traverse_Print(head->next);cout<<head->item<<" ";}




0 0
原创粉丝点击