// una semplice implementazione delle pile public class Pila{ private L list; public Pila (){ list = null; } public void push(int x){ list = new L(x, list); } public int top(){ if (list == null){ throw new IllegalAccessError("pila vuota"); } else{ return list.head(); } } public void pop(){ if (list == null){ throw new IllegalAccessError("pila vuota"); } else{ list = list.tail(); } } public boolean isEmpty(){ if (list == null) return true; else return false; } // public String toString(){ // if (list == null){ // return "[]"; // } // else{ // return list.toString(); // } // } private String stp(L l){ if (l == null) return " --"; else return " "+l.head() + "\n" +stp(l.tail()); } public String toString(){ return stp(list); } }