模拟栈&&模拟队列

模拟栈:
class Stack {
  private List list = new ArrayList( );
  public void push( Object obj ) {
  this.list.add( this.list.size( ), obj );
  }
  public Object pop( ) {
  return this.list.remove( this.list.size( ) - 1 );
  }
  public Object get( ) {
  return this.list.get( this.list.size( ) - 1 );
  }
}

模拟队列:
class Queue {
  private List list = new LinkedList( );
  public void enQueue( Object obj ) {
    this.list.add( this.list.size( ), obj );

  }
  public Object deQueue( ) {
  return this.list.remove( 0 );
  }
  public Object get( ) {
  return this.list.get( 0 );
  }
}

posted @ 2018-12-11 14:32  黑魔法os  阅读(136)  评论(0编辑  收藏  举报