AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.Stack< T > Class Template Reference

Implementation of a stack based on aud.Vector. More...

+ Inheritance diagram for aud.Stack< T >:
+ Collaboration diagram for aud.Stack< T >:

Public Member Functions

 Stack ()
 
boolean is_empty ()
 Is stack empty? More...
 
top () throws NoSuchElementException
 Get stack top. More...
 
pop () throws NoSuchElementException
 Pop element from stack. More...
 
void push (T x)
 Push x onto stack. More...
 
- Public Member Functions inherited from aud.adt.AbstractStack< T >
abstract boolean is_empty ()
 Is stack empty? More...
 
abstract T top ()
 Get stack top. More...
 
abstract T pop ()
 Pop element from stack. More...
 
abstract void push (T x)
 Push x onto stack. More...
 
String toString ()
 Get string representation "|a|b|c". More...
 

Additional Inherited Members

- Protected Member Functions inherited from aud.adt.AbstractStack< T >
 AbstractStack ()
 create empty stack More...
 

Detailed Description

Implementation of a stack based on aud.Vector.

Definition at line 8 of file Stack.java.

Constructor & Destructor Documentation

◆ Stack()

aud.Stack< T >.Stack ( )

Definition at line 11 of file Stack.java.

11{ data_=new Vector<T>(); }

Member Function Documentation

◆ is_empty()

boolean aud.Stack< T >.is_empty ( )

Is stack empty?

Reimplemented from aud.adt.AbstractStack< T >.

Definition at line 14 of file Stack.java.

14{ return data_.empty(); }

Referenced by aud.example.IterativePreorderTraversal.iterative_traversal(), aud.example.graph.IterativeDFS1.start(), aud.example.graph.IterativeDFS2.start(), aud.test.StackTest.testStack(), and aud.example.VerboseStack< T >.toString().

+ Here is the caller graph for this function:

◆ pop()

T aud.Stack< T >.pop ( ) throws NoSuchElementException

Pop element from stack.

Requires !is_empty().

Exceptions
NoSuchElementException
Returns
removed element

Reimplemented from aud.adt.AbstractStack< T >.

Reimplemented in aud.example.VerboseStack< T >.

Definition at line 23 of file Stack.java.

23 {
24 if (data_.empty())
25 throw new NoSuchElementException();
26 T obj=data_.back();
27 data_.pop_back();
28 return obj;
29 }

Referenced by aud.example.graph.IterativeDFS1.start(), aud.example.graph.IterativeDFS2.start(), aud.test.StackTest.testInvalid_pop(), and aud.test.StackTest.testStack().

+ Here is the caller graph for this function:

◆ push()

void aud.Stack< T >.push ( x)

Push x onto stack.

Parameters
xnew element

Reimplemented from aud.adt.AbstractStack< T >.

Reimplemented in aud.example.VerboseStack< T >.

Definition at line 31 of file Stack.java.

31 {
32 data_.push_back(x);
33 }

Referenced by aud.example.grid.Grid.dfs_iterative(), aud.example.graph.IterativeDFS1.start(), aud.example.graph.IterativeDFS2.start(), and aud.test.StackTest.testStack().

+ Here is the caller graph for this function:

◆ top()

T aud.Stack< T >.top ( ) throws NoSuchElementException

Get stack top.

Requires !is_empty().

Exceptions
NoSuchElementException
Returns
top

Reimplemented from aud.adt.AbstractStack< T >.

Definition at line 17 of file Stack.java.

17 {
18 if (data_.empty())
19 throw new NoSuchElementException();
20 return data_.back();
21 }

Referenced by aud.test.StackTest.testInvalid_top(), and aud.test.StackTest.testStack().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: