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

首頁 > 學院 > 開發設計 > 正文

不得已一 維護一個棧并維護棧的最小元素getMin

2019-11-14 10:58:10
字體:
來源:轉載
供稿:網友

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; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 循化| 新干县| 乡城县| 廊坊市| 庆城县| 伊宁市| 门源| 惠来县| 伊通| 苏尼特右旗| 湟源县| 连山| 永济市| 平和县| 通河县| 平和县| 托克托县| 嘉荫县| 斗六市| 凤城市| 桐城市| 自贡市| 大港区| 香港 | 隆德县| 孟州市| 临安市| 怀化市| 宜春市| 临邑县| 铜梁县| 定边县| 闻喜县| 叶城县| 波密县| 田林县| 满洲里市| 岳池县| 锦屏县| 大悟县| 长宁区|