Implementation of a stack as a linked list.
More...
Go to the source code of this file.
Implementation of a stack as a linked list.
- Author
- Rui Carlos Gonçalves
- Version
- 3.0.1
- Date
- 01/2014
Definition in file stack.c.
Creates a stack.
- Returns
NULL
if an error occurred
the new stack otherwise
Definition at line 13 of file stack.c.
void stackDelete |
( |
Stack |
stack | ) |
|
Deletes a stack.
- Attention
- This function only frees the memory used by the stack. It does not free the memory used by elements the stack contains.
- Parameters
-
stack | the stack to be deleted |
Definition at line 26 of file stack.c.
Creates an iterator from a stack.
- See Also
- Iterator
- Parameters
-
- Returns
NULL
if an error occurred
the iterator otherwise
Definition at line 122 of file stack.c.
int stackMap |
( |
Stack |
stack, |
|
|
void(*)(void *) |
fun |
|
) |
| |
Applies a function to the elements of a stack.
The function to be applied must be of type void fun(void*)
.
- Parameters
-
stack | the stack |
fun | the function to be applied |
- Returns
- 0 if the stack was not empty
1 otherwise
Definition at line 105 of file stack.c.
int stackPop |
( |
Stack |
stack, |
|
|
void ** |
value |
|
) |
| |
Removes an elements from the top of a stack.
Provides the value of the removed element if the value of value
is not NULL
.
- Attention
- This function does not free the memory used by the removed element.
- Parameters
-
stack | the stack |
value | pointer where the removed value should be put (or NULL ) |
- Returns
- 0 if the element was removed
1 if the stack was empty
Definition at line 62 of file stack.c.
int stackPush |
( |
Stack |
stack, |
|
|
void * |
value |
|
) |
| |
Inserts an element at the top of the stack.
- Parameters
-
stack | the stack |
value | the value to be inserted |
- Returns
- 0 if the new value was inserted
1 if it was not possible to insert the new element
Definition at line 44 of file stack.c.
int stackSize |
( |
Stack |
stack | ) |
|
Returns the size of a stack.
- Parameters
-
- Returns
- the size of the stack
Definition at line 98 of file stack.c.
int stackTop |
( |
Stack |
stack, |
|
|
void ** |
value |
|
) |
| |
Provides the value of the element at the top of a stack.
If the stack is empty, it will be put the value NULL
at value
.
- Attention
- This function puts at
value
a pointer to the value at the top. Changes to this value will affect the element in the stack.
- Parameters
-
stack | the stack. |
value | pointer where the value at the first position will be put |
- Returns
- 0 if the stack was not empty
1 otherwise
Definition at line 84 of file stack.c.