首页 > 编程知识 正文

单链表反转c++,双向链表c语言解析

时间:2023-05-03 21:38:03 阅读:33526 作者:2085

# include stdio.hstructlistnode { int data; 结构列表*下一步; (; 结构列表* reverse list (结构列表* head ) if(head==null||head-next==null ) { return head; }结构列表* previous=null; 结构列表* next=null; wile (头!=null}{next=head-next; 头下一个=previous; previous=head head=next; }返回预览; } voidprintlist (结构列表头while )头!=null(printf('%d ',头数据); head=head-next; }printf((n ); } voiddestroylist (结构列表头if ) head==null ) { return; }结构列表* tmp=head; wile (头!=null}{tmp=head; head=head-next; 删除时间; }}int main () structlistnode*ln=newlistnode ); 结构列表* head=ln; ln-data=1; for(intI=2; i8; I ) ln-next=新列表); ln=ln-next; ln-data=i; (} ln-next=NULL; 打印列表(head; 结构列表*新头部=reverse list (head; 打印列表(新头); estroylist (新头部); } CLion 2020的执行结果

/users/Cao Chenghua/clion projects/navinfo/cmake-build-debug/navinfo

1 2 3 4 5 6 7

7 6 5 4 3 2 1

处理完成的with exit代码0

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。