📄 stack-01.java
字号:
//=====================程序描述==================
//程序名称:stack-01.java
//程序目的:数组模拟的堆栈
//作者:张中强
//=====================程序描述==================
class statck01
{
public static void main(String args[])
{
Stack student=new Stack();
student.push("张三");
student.push("李四");
student.push("王五");
System.out.println(student.pop());
System.out.println(student.pop());
System.out.println(student.pop());
//System.out.println(student.pop());
}
}
class Stack
{
String[] str=new String[10];
int top=-1;//栈指针
public void push(String value)
{
//检查栈中是否有空间
if(top==9)
{
System.out.println("栈空间已满!");
return;
}
top++;
str[top]=value;
}
public String pop()
{
if(top==-1)
{
System.out.println("栈为空!");
return "";
}
return str[top--];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -