链表逆序 和 寻找链表中间节点
2016-05-08 09:58
281 查看
已知链表的头节点为head,写一个函数把链表逆序。
void reserve(list_node* head){ if(head == NULL) return 0; list_node* p = head; list_node* q = p->next; list_node* r = NULL; while(q){ r = q->next; q->next = p; p = q; q = r; } head->next == NULL; head = p; }
找出单链表的中间节点
list_node* findMiddleNode(list_node* head){ if(head == NULL || head->next == NULL){ return 0; } list_node* p = head; list_node* q = head; while(q->next!=NULL&&q->next->next!=NULL){ p = p->next; q = q ->next->next; } return p; }
相关文章推荐
- vtk实战(五十四)—对直线设置颜色
- GreenDao 使用教程 二
- Winner
- eclipse上hadoop源码阅读
- (1) Centos 7 install VirtualBox guest additions
- ubuntu14下python导入第三方so文件的路径问题
- Nginx 虚拟主机 VirtualHost 配置
- Android中使用ViewPager实现图片的切换
- Geek-Band--第十周分享
- 当使用使用SpringBoot时,要继承SpringBoot的POM的原因
- C++实验5-数组的分离
- 集合概述
- win32汇编 invoke 和 call区别
- springcloud(第五篇)springcloud turbine
- tar.xz文件如何解压
- iOS开发:UIBarButtonItem的简单用法
- 【转】${sessionScope.user}的使用方法
- MySQL开发规范和原则大全
- SQL多表连接查询
- Redis源码解析:18Hiredis同步API和回复解析API代码解析