Humboldt-Universität zu Berlin - Mathematisch-Naturwissenschaftliche Fakultät - Algorithm Engineering

Element.java

text/x-java Element.java — 1.0 KB

Dateiinhalt

/**
 * An element in a stack that wraps an integer.
 */
public class Element {
	private final int value;
	private Element next;

	/**
	 * A constructor for creating a new element.
	 * 
	 * @param value
	 *            the integer value that is to be wrapped by this element
	 */
	public Element(int value) {
		this.value = value;
	}

	/**
	 * Sets the pointer to the next element in the stack.
	 * 
	 * @param next
	 *            the next element in the stack
	 */
	public void setNext(Element next) {
		this.next = next;
	}

	/**
	 * Tests whether there is a next element.
	 * 
	 * @return true, if there is a next element, false otherwise
	 */
	public boolean hasNext() {
		return next != null;
	}

	/**
	 * Returns the next element in the stack.
	 * 
	 * @return the next element in the stack
	 */
	public Element getNext() {
		return next;
	}

	/**
	 * Returns the integer value that is wrapped by this element.
	 * 
	 * @return the integer value that is wrapped by this element
	 */
	public int getValue() {
		return value;
	}
}