implement|implement stack by arrayList
【implement|implement stack by arrayList】模拟一个arraylist, 就是 FI LO
public class Stack {/** @param x: An integer* @return: nothing*/private Listlist = new ArrayList<>();
public void push(int x) {
// write your code here
list.add(x);
}
/*
* @return: nothing
*/
public void pop() {
// write your code here
list.remove(list.size() - 1);
}
/*
* @return: An integer
*/
public int top() {
// write your code here
return list.get(list.size() - 1);
}
/*
* @return: True if the stack is empty
*/
public boolean isEmpty() {
// write your code here
return list.size() <= 0;
}
}
推荐阅读
- Java内存泄漏分析系列之二(jstack生成的Thread|Java内存泄漏分析系列之二:jstack生成的Thread Dump日志结构解析)
- c语言|一文搞懂栈(stack)、堆(heap)、单片机裸机内存管理malloc
- Git|Git branching strategy integated with testing/QA process - Stack Overflow
- java源码赏析--java.util.ArrayList
- Elastic Stack安装部署
- Elastic Stack基础概念
- Elastic Stack概述
- 什么是|什么是 StackBlitz 的 web container
- Java|Java JUC CopyOnWriteArrayList 解析
- java集合【13】——— Stack源码分析走一波