public class EmptyStackException extends RuntimeException {
public EmptyStackException() {
}
public EmptyStackException(String message) {
super(message);
}
}
pop方法
public int pop(){
if(isEmpty()){
throw new EmptyStackException();
}
int val = elem[usedsize - 1];
usedsize--;
return val;
}
private boolean isEmpty(){
return usedsize == 0;
}
实现peek方法
public int peek(){
if(isEmpty()){
throw new EmptyStackException();
}
return elem[usedsize - 1];
}
private boolean isEmpty(){
return usedsize == 0;
}
测试:
public class Test {
//测试MyStack
public static void main1(String[] args) {
MyStack myStack = new MyStack();
myStack.push(1);
myStack.push(2);
myStack.push(3);
myStack.push(4);
myStack.push(5);
System.out.println(myStack.peek());
System.out.println(myStack.pop());
System.out.println(myStack.peek());
}
}
0、Keil MDK报错:Browse information of one or more files is not available----解决方法: 1、使用cubemax生成的工程中,某些引脚自定义了的,是在main.h中,要记得移植。
注意:cubemax生成的spi.c后,在移植的时候,注意hal_driver下面要对应增加hal_stm32H7xxxspi.c
…