package cap9.pilaiterabile;

import cap9.pila.Pila;

public class PilaIterabile extends Pila
{ public PilaIterabile(int max)
  { super(max);
  }
  public PilaIterabile()
  { super();
  }
  public Iterator iteratoreAvanti()
  { return new IteratoreAvanti();
  }
  public Iterator iteratoreIndietro()
  { return new IteratoreIndietro();
  }
  public class IteratoreIndietro implements Iterator
  { private int pos = top;
    public boolean hasNext()
    { if(pos >= 0)
        return true;
      return false;
    }
    public Object next()
    { if (pos >= 0)
        return v[pos--];
      else 
        return null; 
    }
  }
  public class IteratoreAvanti implements Iterator
  { private int pos = 0;
    public boolean hasNext()
    { if(pos <= top)
        return true;
      return false;
    }
    public Object next()
    { if (pos <= top)
        return v[pos++];
      else 
        return null;
    }
  }
}
