public class Stack{
static int top = 0;
static Element[] stack = new Element[10];
static class Element {
int body;
Element(int value){
body = value;
}
}
public static void main(String[] args){
push(5);
System.out.println(top);
push(7);
System.out.println(top);
poll();
System.out.println(top);
poll();
System.out.println(top);
}
private static void push(int value){
Element newElement = new Element(value);
top++;
}
private static Element poll(){
Element topElement = stack[top];
top--;
return topElement;
}
}
|