// Stackクラス(固定長配列を使って定義)
public class Stack{
private int pos; // 次に要素が入る位置
private int top; // スタックの最上位の位置
private String size[] = new String[100]; // スタックの大きさ
public String toString(){
if(this.pos == 0) return ("スタックは空です");
String s = size[0];
for(int i=1; i < pos; i++){
s = size[i] + " <-- " + s;
}
return s;
}
// スタックの内容を出力する
public void show(){
System.out.println(this.toString());
}
}
public class TestStack{
public static void main(String[] args){
Stack s = new Stack(); //スタックの作成
s.show(); //初期状態
s.push("a");
s.push("b");
s.push("c");
s.pop();
s.push("d");
s.show();
}
}