diff --git a/MCA算法突击课/第03期/ppt/key/第01节.key b/MCA算法突击课/第03期/ppt/key/第01节.key new file mode 100644 index 0000000..42230df Binary files /dev/null and b/MCA算法突击课/第03期/ppt/key/第01节.key differ diff --git a/MCA算法突击课/第03期/ppt/key/第02节.key b/MCA算法突击课/第03期/ppt/key/第02节.key new file mode 100644 index 0000000..e5bf858 Binary files /dev/null and b/MCA算法突击课/第03期/ppt/key/第02节.key differ diff --git a/MCA算法突击课/第03期/ppt/powerpoint/第01节.pptx b/MCA算法突击课/第03期/ppt/powerpoint/第01节.pptx new file mode 100644 index 0000000..743804b Binary files /dev/null and b/MCA算法突击课/第03期/ppt/powerpoint/第01节.pptx differ diff --git a/MCA算法突击课/第03期/ppt/powerpoint/第02节.pptx b/MCA算法突击课/第03期/ppt/powerpoint/第02节.pptx new file mode 100644 index 0000000..d9017dd Binary files /dev/null and b/MCA算法突击课/第03期/ppt/powerpoint/第02节.pptx differ diff --git a/体系学习班/class03/Code05_GetMinStack.java b/体系学习班/class03/Code05_GetMinStack.java index 91b20ae..9208e59 100644 --- a/体系学习班/class03/Code05_GetMinStack.java +++ b/体系学习班/class03/Code05_GetMinStack.java @@ -9,35 +9,33 @@ public class Code05_GetMinStack { private Stack stackMin; public MyStack1() { - this.stackData = new Stack(); - this.stackMin = new Stack(); + stackData = new Stack(); + 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); + if (stackMin.isEmpty() || newNum <= this.getmin()) { + stackMin.push(newNum); } - this.stackData.push(newNum); + stackData.push(newNum); } public int pop() { - if (this.stackData.isEmpty()) { + if (stackData.isEmpty()) { throw new RuntimeException("Your stack is empty."); } - int value = this.stackData.pop(); - if (value == this.getmin()) { - this.stackMin.pop(); + int value = stackData.pop(); + if (value == getmin()) { + stackMin.pop(); } return value; } public int getmin() { - if (this.stackMin.isEmpty()) { + if (stackMin.isEmpty()) { throw new RuntimeException("Your stack is empty."); } - return this.stackMin.peek(); + return stackMin.peek(); } } @@ -46,35 +44,32 @@ public class Code05_GetMinStack { private Stack stackMin; public MyStack2() { - this.stackData = new Stack(); - this.stackMin = new Stack(); + stackData = new Stack(); + 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); + if (stackMin.isEmpty() || newNum < getmin()) { + stackMin.push(newNum); } else { - int newMin = this.stackMin.peek(); - this.stackMin.push(newMin); + stackMin.push(stackMin.peek()); } - this.stackData.push(newNum); + stackData.push(newNum); } public int pop() { - if (this.stackData.isEmpty()) { + if (stackData.isEmpty()) { throw new RuntimeException("Your stack is empty."); } - this.stackMin.pop(); - return this.stackData.pop(); + stackMin.pop(); + return stackData.pop(); } public int getmin() { - if (this.stackMin.isEmpty()) { + if (stackMin.isEmpty()) { throw new RuntimeException("Your stack is empty."); } - return this.stackMin.peek(); + return stackMin.peek(); } } @@ -91,7 +86,7 @@ public class Code05_GetMinStack { System.out.println("============="); - MyStack1 stack2 = new MyStack1(); + MyStack2 stack2 = new MyStack2(); stack2.push(3); System.out.println(stack2.getmin()); stack2.push(4);