java豆子

导航

java实现栈-使用LinkedList

 

import java.util.LinkedList;

public class LinkedListStack {

  public static void main(String[] args) {
     myStack stack = new myStack();
        for (int i = 0; i < 10; i++){
           stack.push(i);
        }         
        System.out.println(stack.top());
        System.out.println(stack.top());
        }

}
class myStack extends LinkedList{
  public void push(Object v){
    this.addLast(v);
  }
  public Object pop(){
    return this.removeFirst();
    
  }
  public Object top(){
    return this.getFirst();
    
  }
}

 

posted on 2013-12-16 19:55  java豆子  阅读(794)  评论(0编辑  收藏  举报