資源簡(jiǎn)介

代碼片段和文件信息
package?chapter_1_stackandqueue;
import?java.util.Stack;
public?class?Problem_01_GetMinStack?{
public?static?class?MyStack1?{
private?Stack?stackData;
private?Stack?stackMin;
public?MyStack1()?{
this.stackData?=?new?Stack();
this.stackMin?=?new?Stack();
}
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;
}
public?int?getmin()?{
if?(this.stackMin.isEmpty())?{
throw?new?RuntimeException(“Your?stack?is?empty.“);
}
return?this.stackMin.peek();
}
}
public?static?class?MyStack2?{
private?Stack?stackData;
private?Stack?stackMin;
public?MyStack2()?{
this.stackData?=?new?Stack();
this.stackMin?=?new?Stack();
}
public?void?push(int?newNum)?{
if?(this.stackMin.isEmpty())?{
this.stackMin.push(newNum);
}?else?if?(newNum? this.stackMin.push(newNum);
}?else?{
int?newMin?=?this.stackMin.peek();
this.stackMin.push(newMin);
}
this.stackData.push(newNum);
}
public?int?pop()?{
if?(this.stackData.isEmpty())?{
throw?new?RuntimeException(“Your?stack?is?empty.“);
}
this.stackMin.pop();
return?this.stackData.pop();
}
public?int?getmin()?{
if?(this.stackMin.isEmpty())?{
throw?new?RuntimeException(“Your?stack?is?empty.“);
}
return?this.stackMin.peek();
}
}
public?static?void?main(String[]?args)?{
MyStack1?stack1?=?new?MyStack1();
stack1.push(3);
System.out.println(stack1.getmin());
stack1.push(4);
System.out.println(stack1.getmin());
stack1.push(1);
System.out.println(stack1.getmin());
System.out.println(stack1.pop());
System.out.println(stack1.getmin());
System.out.println(“=============“);
MyStack1?stack2?=?new?MyStack1();
stack2.push(3);
System.out.println(stack2.getmin());
stack2.push(4);
System.out.println(stack2.getmin());
stack2.push(1);
System.out.println(stack2.getmin());
System.out.println(stack2.pop());
System.out.println(stack2.getmin());
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????????257??2015-09-02?14:44??說(shuō)明.txt
?????目錄???????????0??2018-12-21?15:39??BookCode\
?????文件?????????295??2018-07-23?17:15??BookCode\.classpath
?????文件?????????367??2018-11-15?21:56??BookCode\.project
?????目錄???????????0??2018-12-21?15:39??BookCode\.settings\
?????文件?????????587??2018-07-23?17:15??BookCode\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2018-12-13?14:55??BookCode\src\
?????目錄???????????0??2018-12-21?15:39??BookCode\src\chapter_1_stackandqueue\
?????文件????????2424??2018-07-23?17:47??BookCode\src\chapter_1_stackandqueue\Problem_01_GetMinStack.java
?????文件????????1281??2018-07-23?18:24??BookCode\src\chapter_1_stackandqueue\Problem_02_TwoStacksImplementQueue.java
?????文件?????????787??2018-07-23?17:18??BookCode\src\chapter_1_stackandqueue\Problem_03_ReverseStackUsingRecursive.java
?????文件????????3195??2018-07-23?17:18??BookCode\src\chapter_1_stackandqueue\Problem_04_DogCatQueue.java
?????文件?????????867??2018-07-23?17:18??BookCode\src\chapter_1_stackandqueue\Problem_05_StackSortStack.java
?????文件????????3168??2018-07-23?17:18??BookCode\src\chapter_1_stackandqueue\Problem_06_HanoiStack.java
?????文件?????????960??2018-07-23?17:18??BookCode\src\chapter_1_stackandqueue\Problem_07_SlidingWindowMaxArray.java
?????文件????????4011??2018-11-15?18:06??BookCode\src\chapter_1_stackandqueue\Problem_08_MonotonousStack.java
?????文件????????1370??2018-11-15?18:07??BookCode\src\chapter_1_stackandqueue\Problem_09_MaximalRectangle.java
?????文件????????2373??2018-11-15?18:07??BookCode\src\chapter_1_stackandqueue\Problem_10_AllLessNumSubArray.java
?????文件????????6165??2018-11-15?18:07??BookCode\src\chapter_1_stackandqueue\Problem_11_VisibleMountains.java
?????目錄???????????0??2018-12-21?15:40??BookCode\src\chapter_2_listproblem\
?????文件????????1242??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_01_PrintCommonPart.java
?????文件????????2976??2018-07-23?17:31??BookCode\src\chapter_2_listproblem\Problem_02_RemoveLastKthNode.java
?????文件????????1650??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_03_RemoveNodeByRatio.java
?????文件????????1958??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_04_ReverseList.java
?????文件????????1781??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_05_ReversePartList.java
?????文件????????2059??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_06_JosephusProblem.java
?????文件????????5347??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_07_IsPalindromeList.java
?????文件????????2872??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_08_SmallerEqualBigger.java
?????文件????????2909??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_09_CopyListWithRandom.java
?????文件????????2329??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_10_AddTwoli
?????文件????????3748??2018-07-23?17:18??BookCode\src\chapter_2_listproblem\Problem_11_FindFirstIntersectNode.java
............此處省略163個(gè)文件信息
評(píng)論
共有 條評(píng)論