java实现单链表之逆序
作者:mrr 时间:2023-05-03 02:01:54
下面一段代码准确的介绍了java实现单链表逆序,具体内容就不做详解了,有需要的朋友可以直接拷贝了
package com.ckw.mianshi;/** * java 实现单链表的逆序 * @author Administrator * */public class SingleLinkedReverse { class Node{ int data; Node next; public Node(int data){ this.data = data; } } public static void main(String[] args) { SingleLinkedReverse slr = new SingleLinkedReverse(); Node head, tail; head = tail = slr.new Node(0); for(int i=1; i<10; i++){ Node p = slr.new Node(i); tail.next = p; tail = p; } tail = head; while(tail != null){ System.out.print(tail.data+ ); tail = tail.next; } head = reverse(head); System.out.println( ); while(head != null){ System.out.print(head.data+ ); head = head.next; } } private static Node reverse(Node head) { Node p1,p2 = null; p1 = head; while(head.next != null){ p2 = head.next; head.next = p2.next; p2.next = p1; p1 = p2; } return p2; }}测试结果:0 1 2 3 4 5 6 7 8 99 8 7 6 5 4 3 2 1 0以上是java实现单链表逆序的代码,希望大家能够喜欢。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring Boot Actuator管理日志的实现
![](https://img.aspxhome.com/file/2023/0/132140_0s.png)
springMVC实现图形验证码(kaptcha)代码实例
为何Linq的Distinct实在是不给力
![](https://img.aspxhome.com/file/2023/8/113798_0s.png)
在Eclipse中使用版本管理工具SVN的图文教程
![](https://img.aspxhome.com/file/2023/1/61541_0s.png)
Java通过匿名类来实现回调函数实例总结
宝塔面板配置及部署javaweb教程(全网最全)
![](https://img.aspxhome.com/file/2023/5/58905_0s.jpg)
java多线程中执行多个程序的实例分析
android 实现控件左右或上下抖动教程
Java如何实现自定义异常类
Android实现单页面浮层可拖动view的示例代码
![](https://img.aspxhome.com/file/2023/6/139366_0s.png)
基于android studio的layout的xml文件的创建方式
![](https://img.aspxhome.com/file/2023/3/138563_0s.jpg)
Matlab实现获取文件夹下所有指定后缀的文件
![](https://img.aspxhome.com/file/2023/5/120825_0s.png)
详解java中各类锁的机制
![](https://img.aspxhome.com/file/2023/3/71233_0s.jpg)
Jetpack Compose修饰符专项精讲
![](https://img.aspxhome.com/file/2023/4/103884_0s.png)
springboot配置文件的加载顺序解析
![](https://img.aspxhome.com/file/2023/5/72345_0s.png)
一文搞懂Java创建线程的五种方法
![](https://img.aspxhome.com/file/2023/3/58693_0s.png)
Android编程开发之Spinner组件用法
Java回调方法详解
Java深入了解数据结构之二叉搜索树增 插 删 创详解
![](https://img.aspxhome.com/file/2023/4/60794_0s.png)