栈:先进后出(后进先出)
继承了MyArrayList类来实现功能
package com.stack;
import com.array.MyArrayList;
public class MyStack extends MyArrayList {
//入栈
public void push(Object ele){
super.add(ele);
}
//出栈,删除栈顶的元素
public void pop(){
int index = super.size()-1;
super.deletePlayerByIndex(index);
}
//查询栈顶元素
public Object peek(){
int index = super.size()-1;
return get(index);
}
public static void main(String[] args) {
MyStack stack = new MyStack();
stack.push("D");
stack.push("C");
stack.push("B");
stack.push("A");
System.out.println(stack);
System.out.println(stack.peek());
stack.pop();
System.out.println(stack);
}
}