JAvaスタック実装
923 ワード
package stack;
public class Stack {
private int maxSize;
private int[] stackArray;
private int top;
public Stack(int maxSize) {
maxSize = maxSize;
stackArray = new int[maxSize];
top = -1;
}
public void push(int i) {
stackArray[++top] = i;
}
public int pop() {
return stackArray[top--];
}
public int peak() {
return stackArray[top];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
public static void main(String[] args) {
Stack stack = new Stack(10);
for (int i = 0; i < 10; i++) {
stack.push(i);
}
while (!stack.isEmpty()) {
System.out.println(stack.pop());
}
}
}