国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

不得已一 維護(hù)一個(gè)棧并維護(hù)棧的最小元素getMin

2019-11-14 11:02:44
字體:
供稿:網(wǎng)友

github:https://github.com/cbamls 歡迎加入 (java)全國各校IT精英 QQ群號: 467123855

package com.offer.chapter1;import java.util.Stack;/** * CopyRright (c)2014-2016 Haerbin Hearglobal Co.,Ltd * PRoject: demo * Comments: * Author:cbam * Create Date:2017/2/4 * Modified By: * Modified Date: * Modified Reason: */public class Problem_01_MyStack1 { private Stack<Integer> stackData; private Stack<Integer> stackMin; public Problem_01_MyStack1() { this.stackData = new Stack<>(); this.stackMin = new Stack<>(); } public int getMin() { if(this.stackMin.isEmpty()) { throw new RuntimeException("Your stack is empty"); } return this.stackMin.peek(); } public void push(int newNum) { if(this.stackMin.isEmpty()) { this.stackMin.push(newNum); } else if(newNum <= this.getMin()) { this.stackMin.push(newNum); } this.stackData.push(newNum); } public int pop() { if(this.stackData.isEmpty()) { throw new RuntimeException("Your stack is empty"); } int value = this.stackData.pop(); if(value == this.getMin()) { this.stackMin.pop(); } return value; }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 泗阳县| 万盛区| 宝兴县| 巨野县| 宜章县| 兴山县| 浦城县| 桃园县| 定州市| 郴州市| 象州县| 墨竹工卡县| 乌审旗| 仙游县| 大邑县| 喀喇沁旗| 高邑县| 南和县| 芦山县| 桦南县| 琼中| 洛川县| 黄陵县| 铜鼓县| 房产| 灵宝市| 平凉市| 永丰县| 武川县| 庄河市| 德昌县| 巴里| 鄂伦春自治旗| 祁门县| 大余县| 渭南市| 潞城市| 岑巩县| 东乌| 哈尔滨市| 友谊县|