AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
AbstractStack.java
Go to the documentation of this file.
1package aud.adt;
2
3import java.util.NoSuchElementException;
4
8public abstract class AbstractStack<T> {
9
11 protected AbstractStack() {}
12
14 public abstract boolean is_empty();
15
21 public abstract T top();
22
28 public abstract T pop();
29
33 public abstract void push(T x);
34
39 @Override
40 public String toString() {
41 if (!is_empty()) {
42 T x=pop();
43 String bottom=toString();
44 push(x);
45 return (bottom+(bottom.length()>1 ? "|":""))+x;
46 }
47 else
48 return "|";
49 }
50}
Interface for an ADT stack.
AbstractStack()
create empty stack
abstract T top()
Get stack top.
abstract boolean is_empty()
Is stack empty?
abstract void push(T x)
Push x onto stack.
abstract T pop()
Pop element from stack.
String toString()
Get string representation "|a|b|c".