一、栈 Stack(存取O(1)) 先进后出,进去123,出来321。 基于数组:最后一位为栈尾,用于取操作。 基于链表:第一位为栈尾,用于取操作。 /** * 基于数组实现的顺序栈; items[0]:表头/栈底; items[size-1]:表尾/栈顶; */ public class MyArrayStack { // 存储元素的 数组 private String items[]; // 栈实际大小 private int size =0; // 栈的容量 private int capacity = 0; public MyArrayStack(int capacity) { this.size = 0; this.capacity = capacity; this.items = new String[capacity]; } /** * 入栈 */ public boolean push(String item) { if(size >= capacity){ throw new IndexOutOfBoundsException("MyArrayStack...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with return
Contact return, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack