package com.hephec;
import java.util.*;
public class Statck<T>{
private LinkedList<T> storage=new LinkedList<T>();
public void push(T v){storage.addFirst();}
public T peek(){return storage.getFirst();}
public T pop(){return storage.removeFirst();}
public boolean isEmpty(){return storage.isEmpty();}
public String toString(){return storage.toString();}
}
实例:
public class StackTest{
public static void main(String[] args){
Stack(String) stack=new Stack<String>();
for(String s:"My dog has fleas".split(" ")){
stack.push(s);}
while(!stack.empty()){
System.out.println(stack.pop()+" ");
}
}
}