模拟栈:
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 );
}
}