Stack

Stack implementation based on Array.

Members

Functions

free
void free()

Free memory allocated by Stack.

pop
T pop()

Pop top element out.

pop
bool pop(T value)

Non-throwing version of pop.

push
void push(T v)

Push element to stack.

top
T top()

Top stack element. Note: Stack must be non-empty.

topPtr
T* topPtr()

Pointer to top stack element. Note: Stack must be non-empty.

Properties

empty
bool empty [@property getter]

Check if stack has no elements.

Examples

import std.exception: assertThrown;

Stack!int s;
assertThrown(s.pop());
s.push(100);
s.push(3);
s.push(76);
assert(s.top() == 76);
int v;
s.pop(v);
assert(v == 76);
assert(s.pop() == 3);
assert(s.pop() == 100);
assert(s.empty);
s.free();

Meta