package com.hb.stack2;
import java.util.LinkedList;
public class Stack2 {
public static void main(String[] args){
Stack2 stack = new Stack2();
stack.push("1");
stack.push("2");
stack.push("3");
stack.push("4");
System.out.print(stack.pop()+" ,");
System.out.print(stack.pop()+" ,");
System.out.print(stack.pop()+" ,");
System.out.print(stack.pop());
}
LinkedList stackArray;
public Stack2(){
this.stackArray = new LinkedList();
}
public void push(Node node){
this.stackArray.add(node);
}
public Node pop(){
if(this.isEmpty())
return null;
Node node = stackArray.getLast();
this.stackArray.remove(stackArray.size()-1);
return node;
}
public boolean isEmpty(){
return stackArray.size()==0;
}
}
class Node{
private E value;
public Node(E value){
this.value = value;
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9474419/viewspace-478449/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9474419/viewspace-478449/