stackapp.java
来自「java 数据结构的一些简单实例和一些线程的应用主要是面向初学者」· Java 代码 · 共 48 行
JAVA
48 行
import java.io.*;
class Stack{
int size;
int[] a;
int top;
public Stack(int value){
size=value;
a=new int[size];
top=-1;
}
public void push(int value){
a[++top]=value;
}
public int pop(){
return a[top--];
}
public int peek(){
return a[top];
}
public boolean isfull(){
return (top==size-1);
}
public boolean isempty(){
return(top==-1);
}
}
public class StackApp{
public static void main(String[] args)throws IOException{
int max=10;
Stack s=new Stack(max);
s.push(10);
s.push(20);
s.push(30);
s.push(40);
while(!s.isempty())
{
int value=s.pop();
System.out.println(value);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?