代码拉取完成,页面将自动刷新
/**
* 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;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。