数据结构与算法之美之栈、队列和递归
栈 栈既可以用数组来实现,也可以用链表来实现。用数组实现的栈,我们叫作顺序栈,用链表实现的栈,我们叫作链式栈 实现方法: package com.smao.leetcode; /** * 数组式链表 */ public class ArrayStack { private String[] arrayStack; private int size;//栈中元素个数 private int count;//栈的容量 public ArrayStack(int count) { this.arrayStack = new String[count]; this.count = count; this.size = 0; } public boolean push(String item){ if(this.count == this.size){ String[] arrayStackNew = new String[this.count*2]; for(int i=0;i<arrayStack.length;i++){ arrayStackNew[i] = arrayStack[i]; this.count = this.count*2; } this.arrayStack = arrayStackNew; } arrayStack[this.size] = item; this