在JAVA中如何实现链表? 是不是用List? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LinkedList就是链表。那能不能给我举个例子呢,谢谢了! class Node { Object data; Node next; public Node(Object data) { setData(data); } public void setData(Object data) { this.data = data; } public Object getData() { return data; }}class Link { Node head; int size = 0; public void add(Object data) { Node n = new Node(data); if (head == null) { head = n; } else { Node current = head; while (true) { if (current.next == null) { break; } current = current.next; } current.next = n; } size++; } public void show() { Node current = head; if (current != null) { while (true) { System.out.println(current); if (current == null) { break; } current = current.next; } } else { System.out.println("link is empty"); } } public Object get(int index) { //.... } public int size() { return size; }} 监听与事件源 小虾米自学java不久遇到一个问题求教~ 谁有在非WEB项目里使用SPRING的例子,拿个来看看吧 大家好,关于打包后安装程序的虚拟机内存问题? ext要收费吗?要多少钱? java连接sql server2000出现的问题急需解决 JTextPane怎么实现文本 不 自动换行? 高手请进. java 用于桌面应用程序开发是否流行? 为什么有的java applet在网页中运行不了! 不规则的字符串 不规则的空格该怎么处理 怎样将Button和键盘上的按键建立起一一对应的关系
Object data;
Node next;
public Node(Object data) {
setData(data);
}
public void setData(Object data) {
this.data = data;
}
public Object getData() {
return data;
}
}
class Link {
Node head;
int size = 0;
public void add(Object data) {
Node n = new Node(data);
if (head == null) {
head = n;
}
else {
Node current = head;
while (true) {
if (current.next == null) {
break;
}
current = current.next;
}
current.next = n;
}
size++;
}
public void show() {
Node current = head;
if (current != null) {
while (true) {
System.out.println(current);
if (current == null) {
break;
}
current = current.next;
}
}
else {
System.out.println("link is empty");
}
}
public Object get(int index) {
//....
}
public int size() {
return size;
}
}