📄 seqstack.java
字号:
//SeqStack.java
class stackException extends Exception
{
stackException()
{
super("堆栈满!");
}
}
public class SeqStack
{
int data[];
int MAX;
int top;
SeqStack(int m)
{
MAX=m;
data=new int [MAX];
top=0;
}
public void push(int item)
{
try
{
if(top==MAX)
throw new stackException();//抛出自定义异常
data[top]=item;
top++;
}
catch(Exception e)
{
System.out.println("exception:"+e.getMessage());
System.exit(0);
}
}
public static void main(String args[])
{
SeqStack stack=new SeqStack(10);
for (int i=0;i<11;i++)
stack.push(i);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -