单链表反转java
来源:互联网 发布:网络吸毒案 编辑:程序博客网 时间:2024/05/22 14:50
public class SingleLinkTest { public static void main(String[] args) { Node node = new Node(0); Node head = node; int i = 1; while(i < 10){ node.next = new Node(i); node = node.next; i++; } Node cur = head; while(cur != null){ System.out.print(cur.data + ","); cur = cur.next; } System.out.println("反转后"); head = reverse(head); cur = head; while(cur != null){ System.out.print(cur.data + ","); cur = cur.next; } System.out.println("反转后"); head = reverseNoDiGui(head); cur = head; while(cur != null){ System.out.print(cur.data + ","); cur = cur.next; } } public static Node reverse(Node node){ if(node == null || node.next == null){ return node; } Node reHead = reverse(node.next); node.next.next = node; node.next = null; return reHead; } public static Node reverseNoDiGui(Node head){ Node pre = head; Node cur = head.next; Node temp; while(cur != null){ temp = cur.next; cur.next = pre; pre = cur; cur = temp; } head.next = null; return pre; }}class Node { public Node(int data) { this.data = data; } public int data; public Node next;}
阅读全文
0 0
- Java单链表反转与部分反转
- Java实现单链表反转
- Java实现反转单链表
- Java-反转单链表
- Java反转单链表
- Java 反转单链表
- java反转单链表
- Java反转单链表(code)
- Java反转单链表(code)
- Java反转单链表
- java反转单链表
- 反转单链表(Java描述)
- 单链表反转--Java实现
- Java实现单链表反转
- java 单链表反转详解
- 单链表反转--java版
- 单链表反转java
- Java单链表反转
- Struts2+MVC+MySql数据库增删查改及分页显示
- 整数排序
- Android Studio 使用教程(十五)之 This support library should not use a different version(x)than the compileS
- NetBean、MyEclipse、Eclipse + Svn/Git 环境搭建和使用比较(详细)
- animate实现单向轨道旋转
- 单链表反转java
- oc中少见的不继承于NSObject 的类NSProxy?
- centos 6.7系统优化
- GitHub代码开源的使用
- org/objectweb/asm/Type异常解决办法
- Spring AOP中pointcut expression表达式解析 及匹配多个条件
- Python爬虫(5)——获取京东手机图片
- 神经大条的Peter---杂①
- 多线程UDP通信(可以自己给自己发)