class Link {
public int data;
public Link next;
public Link(int d) {
data = d;
}
public void displayLink() {
System.out.println(data + "");
}
}
class firstlastList {
private Link first;
private Link last;
public firstlastList() {
first = null;
last = null;
}
public boolean isEmpty() {
return first == null;
}
public void insertfirst(int dd) {
Link newLink = new Link(dd);
if (isEmpty())
last = newLink;
newLink.next = first;
first = newLink;
}
public void insertLast(int dd) {
Link newLink = new Link(dd);
if (isEmpty())
first = newLink;
else
last.next = newLink;
last = newLink;
}
public long deletefirst() {
long temp = first.data;
if (first.next == null)
last = null;
first = first.next;
return temp;
}
public void displayList() {
System.out.println("List(first-->last)");
Link current = first;
while (current != null) {
current.displayLink();
current = current.next;
}
System.out.println("");
}
}
class FirstLastApp {
public static void main(String args[]) {
FirstLastApp theList = new FirstLastApp();
theList.insertfirst(10);
theList.insertfirst(98);
theList.insertfirst(112);
theList.insertLast(123);
theList.insertLast(75);
theList.insertLast(12);
theList.displayList();
theList.deletefirst();
theList.deletefirst();
theList.displayList();
}
}
这一行似乎是一个错误(打字错误?):
FirstLastApp theList = new FirstLastApp();
请尝试更改为:
firstlastList theList = new firstlastList();