Stack¶
| Spice | |
|---|---|
Stack<T> struct¶
A stack in Spice is a commonly used data structure, which uses the FiLo (first in, last out) principle.
Time complexity:
Insert: O(1)
Delete: O(1)
Search: O(n)
Stacks pre-allocate space using an initial size and a resize factor to not have to re-allocate with every item pushed.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a stack pre-filled with a number of copies of a default value
Parameters
| Name | Type | Description |
|---|---|---|
initAllocItems |
unsigned long |
Number of items to insert |
defaultValue |
const T & |
Value to fill the stack with |
ctor¶
| Spice | |
|---|---|
Construct a stack, pre-allocating space for the given number of items
Parameters
| Name | Type | Description |
|---|---|---|
initAllocItems |
unsigned int |
Number of items to pre-allocate space for |
ctor¶
| Spice | |
|---|---|
Construct a stack, pre-allocating space for the given number of items
Parameters
| Name | Type | Description |
|---|---|---|
initAllocItems |
unsigned long |
Number of items to pre-allocate space for (default: INITIAL_CAPACITY) |
ctor¶
| Spice | |
|---|---|
Construct a stack as a deep copy of another stack
Parameters
| Name | Type | Description |
|---|---|---|
original |
const Stack<T>& |
Stack to copy |
Methods¶
push¶
| Spice | |
|---|---|
Add an item to the stack
Parameters
| Name | Type | Description |
|---|---|---|
item |
const T& |
pop¶
| Spice | |
|---|---|
Retrieve item and remove it from the stack
Returns: T&
top¶
| Spice | |
|---|---|
Retrieve topmost without removing it from the stack
Returns: T&
getSize¶
| Spice | |
|---|---|
Retrieve the current size of the stack
Returns: long — Current size of the stack
getCapacity¶
| Spice | |
|---|---|
Retrieve the current capacity of the stack
Returns: long — Current capacity of the stack
isEmpty¶
| Spice | |
|---|---|
Checks if the queue contains any items at the moment
Returns: bool — Empty or not empty
isFull¶
| Spice | |
|---|---|
Checks if the queue exhausts its capacity and needs to resize at the next call of push
Returns: bool — Full or not full
pack¶
| Spice | |
|---|---|
Frees allocated memory that is not used by the queue
Operators¶
operator=¶
| Spice | |
|---|---|
Copy-assign the contents of another stack into this one
Parameters
| Name | Type | Description |
|---|---|---|
newValue |
const Stack<T>& |
Stack to copy from |
operator==¶
| Spice | |
|---|---|
Check if two stacks are equal, i.e. they have the same size and equal contents
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const Stack<T>& |
|
rhs |
const Stack<T>& |
Returns: bool — Equal or not equal
operator!=¶
| Spice | |
|---|---|
Check if two stacks are not equal
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
const Stack<T>& |
|
rhs |
const Stack<T>& |
Returns: bool — Not equal or equal