package study.tables;
import java.util.Objects;
/**
* 单向列表
*/
public class SingleTable<T> {
private static Node head;
public static void add(int value) {
Node node = new Node(value);
if (Objects.isNull(head)) {
head = node;
return;
}
Node cur = head;
while (Objects.nonNull(cur.next)) {
cur = cur.next;
}
cur.next = node;
}
public static void printTableValue() {
Node cur = head;
if (Objects.isNull(cur)) {
return;
}
if (Objects.isNull(cur.next)) {
System.out.println(cur.getValue());
return;
}
while (Objects.nonNull(cur)) {
System.out.println(cur.getValue());
cur = cur.next;
}
}
public static void main(String[] args) {
for (int value = 0; value < 10; value++) {
SingleTable.add(value);
}
printTableValue();
}
}
数据结构与算法 单向列表
最新推荐文章于 2024-10-16 16:34:42 发布