用 LinkedList 实现一个 java.util.Stack 栈
import java.util.LinkedList;
public class Stack<E> {
private LinkedList<E> storage = new LinkedList<>();
public E push(E e) {
storage.addFirst(e);
return e;
}
public E peek() {
return storage.getFirst();
}
public E pop() {
return storage.removeFirst();
}
public boolean empty() {
return storage.isEmpty();
}
public int search(Object o) {
int i = storage.indexOf(o);
if (i >= 0) {
return i + 1;
}
return -1;
}
public int size() {
return storage.size();
}
@Override
public String toString() {
return storage.toString();
}
}
用 LinkedList 实现一个 java.util.Stack 栈
原文:https://www.cnblogs.com/hglibin/p/11391568.html