LinkedList
实现原理:链表
public class MyLinkedList<E> {
class Node {
public E data;//数据区
public Node pointer;//指针区
public Node(E data) {
this.data = data;
pointer = null;
}
}
public static int size = 0; // 元素个数
public Node header = null;
public Node next = null;
// 添加元素
public void add(E item) {
Node node = new Node(item);
size++;
if (header == null) {
header = node;
next = header;
return;
}
next.pointer = node;
next = node; // next指向下一个节点
}
// 获取元素
public E get(int index) {
Node next = null;
next = header;
E data = null;
for (int i = 0; i < size; i++) {
if (index == i) {
data = next.data;
break;
}
next = next.pointer;
}
return data;
}
// 元素个数
public int size() {
return 0;
}