链表 - Java

Infty Lv1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class Intlist {
public int first;
public Intlist rest;

public static void main(String[] args) {
Intlist L = new Intlist(); //L指向一个列表,包含first和rest
L.first = 10;
L.rest = null;

L.rest = new Intlist(); //L.rest指向一个列表,包含L.rest.first和L.rest.rest
L.rest.first = 20;
L.rest.rest = null;

L.rest.rest = new Intlist(); //L.rest.rest指向一个列表,包含L.rest.rest.first和L.rest.rest.rest
L.rest.rest.first = 30;
L.rest.rest.rest = null;
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Intlist {
public int first;
public Intlist rest;

public Intlist(int f, Intlist r) {
first = f;
rest = r;
}

public static void main(String[] args) {
Intlist L = new Intlist(10, null);
L = new Intlist(20, L);
L = new Intlist(30, L);
}
}

  • Title: 链表 - Java
  • Author: Infty
  • Created at : 2025-08-26 01:32:09
  • Updated at : 2025-08-26 02:08:33
  • Link: https://inftys.cn/2025/08/26/java-list/
  • License: This work is licensed under CC BY-SA 4.0.
Comments
On this page
链表 - Java