配列実装3スタック
1503 ワード
方法1
public class ArrayStack {
int stackSize=300;
int []buffer= new int[stackSize*3];
int []stackPointer={-1,-1,-1};
void push(int stackNum,int value)
{
stackPointer[stackNum]++;
int index=stackNum*stackSize+stackPointer[stackNum];
buffer[index]=value;
}
int pop(int stackNum)
{
int index=stackNum*stackSize+stackPointer[stackNum];
stackPointer[stackNum]--;
int value=buffer[index];
buffer[index]=0;
return value;
}
public static void main(String[] args) {
ArrayStack stack=new ArrayStack();
stack.push(0, 1);
stack.push(0, 2);
stack.push(0, 3);
stack.push(0, 4);
System.out.println(stack.pop(0));
}
}