stack.h| Type | |
| The abstract data type for the stack. | |
| Functions | |
| Allocates and returns a new stack, which is initially empty. | |
| Frees the storage associated with the stack. | |
| Pushes the specified element onto the stack. | |
| Pops the top element from the stack and returns that value. | |
| Returns the top element from the stack without removing it. | |
| Tests whether the stack is empty. | |
| Returns the number of elements currently pushed on the stack. | |
| Removes all elements from the stack. | |
| Creates a copy of the stack. | |
typedef struct StackCDT *Stack;
Stack newStack(void);
Usage:
stack = newStack();
void freeStack(Stack stack);
Usage:
freeStack(stack);
void push(Stack stack, void *element);
Usage:
push(stack, element);
void *pop(Stack stack);
pop is called, the
implementation calls error with an appropriate message.
Usage:
element = pop(stack);
void *peek(Stack stack);
pop is called, the
implementation calls error with an appropriate message.
Usage:
element = peek(stack);
bool isEmpty(Stack stack);
Usage:
if (isEmpty(stack)) . . .
int size(Stack stack);
Usage:
n = size(stack);
void clear(Stack stack);
Usage:
clear(stack);
Stack clone(Stack stack);
clone function copies
only the first level of the structure and does not copy the individual
elements.
Usage:
newstack = clone(stack);