51 template<
class E>
class StackPure
56 template<
class ... Args>
71 StackPure(std::initializer_list<E> initList) : m_head(nullptr) {
72 for (
const E &x : initList)
96 bool empty()
const {
return m_head ==
nullptr; }
99 const E &
top()
const {
128 m_head =
new Element(m_head,x);
135 template<
class ... Args>
137 m_head =
new Element(m_head, std::forward<Args>(args)...);
159 void print(ostream &os,
char delim =
' ')
const 164 for(pX = pX->m_next; pX !=
nullptr; pX = pX->m_next)
165 os << delim << pX->m_x;
173 for(
Element *q = S.m_head; q !=
nullptr; q = q->m_next) {
174 *p =
new Element(
nullptr, q->m_x);
204 m_count = initList.size();
225 size_t size()
const {
return m_count; }
265 template<
class ... Args>
283 void print(ostream &os,
char delim =
' ')
const {
293 ostream &operator<<(ostream &os, const StackPure<E> &S)
301 ostream &operator<<(ostream &os, const Stack<E> &S)
void emplace(Args &&... args)
Adds a new element at as top-most element to the stack.
StackPure< E > & operator=(const StackPure< E > &S)
Assignment operator.
Element(Element *pNext, const E &x)
Declaration of memory manager for allocating small pieces of memory.
Stack(const Stack< E > &S)
Constructs a stack that is a copy of S.
void print(ostream &os, char delim=' ') const
StackPure(StackPure< E > &&S)
Constructs a stack containing the elements of S (move semantics).
StackPure< E > & operator=(StackPure< E > &&S)
Assignment operator (move semantics).
void print(ostream &os, char delim=' ') const
const E & top() const
Returns a reference to the top element.
Stack(Stack< E > &&S)
Constructs a stack containing the elements of S (move semantics).
Stack()
Constructs an empty stack.
bool empty() const
Returns true iff the stack is empty.
void emplace(Args &&... args)
Adds a new element at as top-most element to the stack.
Stack< E > & operator=(Stack< E > &&S)
Assignment operator (move semantics).
StackPure(std::initializer_list< E > initList)
Constructs a stack and pushes the elements in initList on it (last element will be on top)...
void push(const E &x)
Adds element x as top-most element to the stack.
StackPure(const StackPure< E > &S)
Constructs a stack that is a copy of S.
E pop()
Removes the top-most element from the stack and returns it.
const E & top() const
Returns a reference to the top element.
void copy(const StackPure< E > &S)
size_t size() const
Returns the number of elements contained in the stack.
void push(const E &x)
Adds element x as top-most element to the stack.
Element(Element *pNext, Args &&... args)
void clear()
Makes the stack empty.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
E & top()
Returns a reference to the top element.
StackPure()
Constructs an empty stack.
const T & move(const T &v)
E pop()
Removes the top-most element from the stack and returns it.
Basic declarations, included by all source files.
Stack< E > & operator=(const Stack< E > &S)
Assignment operator.
void clear()
Makes the stack empty.
Stack(std::initializer_list< E > initList)
Constructs a stack and pushes the elements in initList on it (last element will be on top)...
The namespace for all OGDF objects.
bool empty() const
Returns true iff the stack is empty.
E & top()
Returns a reference to the top element.
size_t size_type
The number of elements in the list.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
The parameterized class Stack<E> implements list-based stacks.