java 逆置 单链表
2015-09-16 12:40
567 查看
[code]public reverseListIteratively (Node head) { if (head == NULL || head.next == NULL) return; //empty or just one node in list Node Second = head.next; //store third node before we change Node Third = Second.next; //Second's next pointer Second.next = head; //second now points to head head.next = NULL; //change head pointer to NULL //only two nodes, which we already reversed if (Third == NULL) return; Node CurrentNode = Third; Node PreviousNode = Second; while (CurrentNode != NULL) { Node NextNode = CurrentNode.next; CurrentNode.next = PreviousNode; /* repeat the process, but have to reset the PreviousNode and CurrentNode */ PreviousNode = CurrentNode; CurrentNode = NextNode; } head = PreviousNode; //reset the head node }
相关文章推荐
- Java学习笔记01 编译和运行Java程序
- Java日期格式转换
- spring利用注解方式实现Java读取properties属性值
- Spring中事务传播行为种类
- java中String为什么是不可变的?
- spring+cxf+hibernate 发布restful WebService服务
- Java复习笔记—基础语法
- Spring MVC3.0.5搭建全程
- Struts2--Interceptors
- MyEclipse 强制杀掉后 INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
- java eclipse导出可运行jar包(java服务)和导入
- MyEclipse 设置字体、关闭html,jsp等页面的可视化编辑器
- JAVA中的Random()函数
- Java swing 项目写成bat文件
- java基础学习笔记--++a与a++以及逻辑运算符
- Java中获取工程路径
- BeagleBone Black第八课板:建立Eclipse编程环境
- JAVA实现简单四则混合运算
- java基础-LinkedList集合
- 企业支付宝账号开发接口教程--JAVA-UTF-8(实际操作------SpringMVC+JSP)