链表结构实现无序列表和有序列表
1. 无序列表的链表实现
在实现无序列表的链表结构之前,我们先来看一个抽象的 LinkedList
类。这个类定义了基于引用的列表的所有构造,且不依赖于列表是否有序。以下是 LinkedList
类的代码:
package ch05.genericLists;
import ch04.genericLists.*;
public abstract class LinkedList implements ListInterface {
protected class ListNode {
protected Listable info;
protected ListNode next;
}
protected ListNode list;
protected int numItems;
protected ListNode currentPos;
public LinkedList() {
numItems = 0;
list = null;
currentPos = null;
}
public boolean isFull() {
return false;
}
public int lengthIs() {
return numItems;
}
public abstract boolean isThere (Listable item