package dataStructure;
/**
* Created by donal on 2017/2/14.
*/
import java.util.LinkedList;
/**
* 1.LinkedList具有能够直接实现栈的所有功能的方法,
* 因此可以直接将LinkedList作为栈使用。
*
* 2.JDK 中 Stack 继承 Vector
* 3.Stack 中有 5个方法
*/publicclass MyStack<T> {
private LinkedList<T> storage = new LinkedList<T>();
publicvoidpush(T v){
storage.addFirst(v);
}
public T pop(){
return storage.removeFirst();
}
public T peek(){
return storage.getFirst();
}
public boolean empty(){
return storage.isEmpty();
}
public String toString(){
return storage.toString();
}
publicstaticvoidmain(String[] args) {
MyStack<String> stack = new MyStack<>();
for (String s : "GeGe da ben dan da a da ben dan!".split(" "))
stack.push(s);
while (!stack.empty())
System.out.println(stack.pop() + " ");
}
}