Java - 实现双向链表
2024-10-08 13:04:39
熟悉一下Java。。。
package ChianTable; import java.util.Scanner; /**
* Created by Administrator on 2018/3/26.
*/
public class LinkedList { private LinkedList prev;
private LinkedList next;
private int val; private LinkedList head;
private LinkedList rear; public LinkedList() {
super();
} public LinkedList(LinkedList p, LinkedList n, int v) {
super();
this.prev = p;
this.next = n;
this.val = v;
} public LinkedList Create() { Scanner type = new Scanner(System.in);
int val = type.nextInt(); LinkedList nextNode = new LinkedList(null, null, val);
this.head = nextNode;
while ((val = type.nextInt()) != 0) {
LinkedList curr = new LinkedList(nextNode, null, val);
nextNode.next = curr;
nextNode = curr;
}
this.rear = nextNode;
nextNode.next = null; return this.head;
} public void nextprint() {
if (this.head != null) {
System.out.println(this.head.val);
this.head = this.head.next;
nextprint();
}
} public void prevprint() {
if (this.rear != null) {
System.out.println(this.rear.val);
this.rear = this.rear.prev;
prevprint();
}
} }
测试:
package main; import ChianTable.LinkedList; public class Main { public static void main(String [] args) { LinkedList linkedlist = new LinkedList(); linkedlist.Create();
linkedlist.nextprint();
linkedlist.prevprint(); }
}
最新文章
- zookeeper集群某个follower启动失败
- zoj 3888 线段树 ***
- Objective-C和其他C指针的转换
- python构建模拟模型——网站独立访问用户数量
- python_day10_IO多路复用
- 折腾了一早上的C# WPF ListView+Grid 实现图片+文字 自动换行排列 类似Windows资源管理器效果
- PAIP.提升效率----论项目知识库的建设。。
- Cmake调用NSIS(一个可执行文件,其实就是一个编译器)编译NSIS脚本问题研究
- git config and options core.bare hard
- (C#)利用Aspose.Cells组件导入导出excel文件
- [51nod1671]货物运输
- selenium+chrome抓取淘宝搜索抓娃娃关键页面
- 五子棋的判断输赢规则 -- java编程(简单优化完整版)
- 计蒜客NOIP模拟赛(2) D2T2紫色百合
- C#线程同步(2)- 临界区&Monitor
- [Android] Android RecycleView和ListView 自定义Adapter封装类
- Scala编程基础
- PHP中一些常用知识点
- ORACLE procedure 一个参数分解成多个字符一点建议
- 22-Python3 输入和输出