import java.util.*;
/**
 * AlgoDat SS00 Aufgabe 46
 * Implementierung eines unbeschraenkten Stack
 * 
 * @author Christian Semrau, 29.04.2000
 * <a href="mailto:Christian.Semrau@student.uni-magdeburg.de">
 * Christian.Semrau@student.uni-magdeburg.de</a>
 */
class MyStack {
    private Vector inhalt;
/**
 * Legt einen neuen Stack an.
 */
public MyStack() {
    inhalt = new Vector();
}
/**
 * Legt einen neuen Stack an und bestimmt die Anfangskapazitaet des Stack.
 */
public MyStack(int initialCapacity) {
    inhalt = new Vector(initialCapacity);
}
/**
 * Liefert genau dann true, wenn der Stack leer ist.
 */
public boolean empty(){
    return inhalt.size()<=0;
}
/**
 * Compares two objects for equality.
 */
public boolean equals(Object obj) {
    // NOTE: obj might be an instance of any class
    return (obj != null && obj instanceof MyStack &&
        ((MyStack)obj).inhalt.equals(inhalt));
}
/**
 * Generates a hash code for the receiver.
 */
public int hashCode() {
    // NOTE: if two objects are equal (equals(Object) returns true)
    // they must have the same hash code
    return inhalt.hashCode() + 21;
}
/**
 * Liefert das oberste Stackelement, ohne es vom Stack zu entfernen.
 */
public Object peek() {
    if (empty())
        throw new EmptyStackException();
    Object ret = inhalt.lastElement();
    return ret;
}
/**
 * Liefert das oberste Stackelement und entfernt es vom Stack.
 */
public Object pop (){
    Object ret = peek();
    inhalt.removeElementAt(inhalt.size()-1);
//    System.out.println(this+" after pop");
    return ret;
}
/**
 * Legt das Objekt oben auf den Stack.
 */
public void push (Object x){
    inhalt.addElement(x);
//    System.out.println(this+" after push");
}
/**
 * Liefert die Anzahl der Elemente auf dem Stack.
 */
public int size() {
    return inhalt.size();
}
/**
 * Returns a String that represents the value of this object.
 */
public String toString() {
    return "MyStack:"+inhalt.toString(); //+"size="+inhalt.size();
}
}