2 Star 1 Fork 0

BESTI.IS.JAVA2018 / 20165334李天龙_JavaProgramming

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
MyList.java 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
林森qubit 提交于 2018-05-05 10:56 . Upload MyList.java Node.java
/**
* Created by 李天龙
*/
import java.util.Iterator;
public class MyList {
public static void main(String[] args) {
//选用合适的构造方法,用你学号前后各两名同学的学号创建四个结点
Node<Integer> S1 = new Node<Integer>(20165332, null);
Node<Integer> S2 = new Node<Integer>(20165333, null);
Node<Integer> S3 = new Node<Integer>(20165335, null);
Node<Integer> S4 = new Node<Integer>(20165336, null);
//把上面四个节点连成一个没有头结点的单链表
S1.next = S2;
S2.next = S3;
S3.next = S4;
//遍历单链表,打印每个结点的
Node<Integer> s = S1;
System.out.println("打印插入前的链表数据");
while (s != null) {
System.out.println(s.data);
s = s.next;
}
//把你自己插入到合适的位置(学号升序)
Node<Integer> M = new Node<Integer>(20165334, null);
s = S1;
while (s != null) {
if (s.data < 20165334 && s.next.data > 20165334) {
M.next = s.next;
s.next = M;
break;
}
else {
s = s.next;
}
}
System.out.println("打印插入自己学号后的链表数据");
//遍历单链表,打印每个结点的
s = S1;
while (s != null) {
System.out.println(s.data);
s = s.next;
}
//从链表中删除自己
s = S1;
while (s != null) {
if (s.next.data == 20165334) {
s.next = s.next.next;
break;
}
else {
s = s.next;
}
}
//遍历单链表,打印每个结点的
System.out.println("打印删除自己学号后的链表数据");
s = S1;
while (s != null) {
System.out.println(s.data);
s = s.next;
}
}
}
1
https://gitee.com/BESTI-IS-JAVA-2018/20165334LiTianLong_JavaProgramming.git
git@gitee.com:BESTI-IS-JAVA-2018/20165334LiTianLong_JavaProgramming.git
BESTI-IS-JAVA-2018
20165334LiTianLong_JavaProgramming
20165334李天龙_JavaProgramming
master

搜索帮助