59 m_pTop = m_pStart = m_pStop =
nullptr;
67 m_pTop = m_pStart - 1;
83 m_pStart = S.m_pStart;
85 S.m_pTop = S.m_pStart = S.m_pStop =
nullptr;
94 const E &
top()
const {
106 INDEX
size()
const {
return (m_pStart !=
nullptr) ? (INDEX)(m_pTop+1 - m_pStart) : 0; }
109 bool empty() {
return m_pTop == (m_pStart-1); }
112 bool full() {
return m_pTop == (m_pStop-1); }
115 bool valid()
const {
return m_pStart !=
nullptr; }
123 m_pTop = m_pStart = m_pStart =
nullptr;
134 m_pTop = m_pStart - 1;
135 m_pStop = m_pStart+n;
154 m_pStart = S.m_pStart;
156 S.m_pTop = S.m_pStart = S.m_pStop =
nullptr;
174 void clear() { m_pTop = m_pStart-1; }
177 void print(ostream &os,
char delim =
' ')
const 179 if(m_pStart !=
nullptr) {
180 for (
const E *pX = m_pStart; pX <=
m_pTop; ++pX)
189 m_pTop = m_pStart = m_pStop =
nullptr;
192 m_pStart =
new E[sz+1];
194 m_pStop = m_pStart + sz;
205 template<
class E,
class INDEX>
206 ostream &operator<<(ostream &os, const BoundedStack<E,INDEX> &S)
BoundedStack(BoundedStack< E > &&S)
Constructs a bounded stack containing the elements of S (move semantics).
void clear()
Makes the stack empty.
BoundedStack< E > & operator=(const BoundedStack< E > &S)
Assignment operator.
E & top()
Returns top element.
#define OGDF_THROW(CLASS)
Replacement for throw.
E * m_pTop
Pointer to top element.
bool full()
Returns true iff the stack is full.
~BoundedStack()
Destruction.
BoundedStack(INDEX n)
Constructs an empty bounded stack for at most n elements.
Definition of exception classes.
void init()
Reinitializes the stack for no elements at all (actually frees memory).
The parameterized class BoundedStack implements stacks with bounded size.
BoundedStack< E > & operator=(BoundedStack< E > &&S)
Assignment operator (move semantics).
E * m_pStart
Pointer to first element.
Exception thrown when not enough memory is available to execute an algorithm.
void copy(const BoundedStack< E > &S)
BoundedStack()
Constructs an empty bounded stack for no elements at all.
const E & top() const
Returns top element.
void init(INDEX n)
Reinitializes the stack for n elements.
INDEX size() const
Returns current size of the stack.
E pop()
Removes the top-most element from the stack and returns it.
void print(ostream &os, char delim=' ') const
Prints the stack to output stream os with the seperator delim.
INDEX capacity() const
Returns the capacity of the bounded stack.
bool valid() const
Returns true iff the stack was initialized.
The namespace for all OGDF objects.
BoundedStack(const BoundedStack< E > &S)
Constructs a bounded stack that is a copy of S.
E * m_pStop
Pointer to one past last element.
bool empty()
Returns true iff the stack is empty.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
void push(const E &x)
Adds element x as top-most element to the stack.