-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.h
70 lines (61 loc) · 1.66 KB
/
stack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* This file contains the definition of an interface for a stack data structure.
*/
#ifndef __STACK_H
#define __STACK_H
/*
* Structure used to represent a stack.
*/
struct stack;
/*
* Creates a new, empty stack and returns a pointer to it.
*/
struct stack* stack_create();
/*
* Free all of the memory associated with a stack. Note that, while this
* function cleans up all memory used in the stack itself, it does not free
* any memory allocated to the pointer values stored in the stack. This is
* the responsibility of the caller.
*
* Params:
* stack - the stack to be destroyed. May not be NULL.
*/
void stack_free(struct stack* stack);
/*
* Returns 1 if the given stack is empty or 0 otherwise.
*
* Params:
* stack - the stack whose emptiness is to be checked. May not be NULL.
*/
int stack_isempty(struct stack* stack);
/*
* Push a new value onto a stack.
*
* Params:
* stack - the stack onto which to push a value. May not be NULL.
* value - the new value to be pushed onto the stack
*/
void stack_push(struct stack* stack, void* value);
/*
* Returns a stack's top value without removing that value from the stack.
*
* Params:
* stack - the stack from which to read the top value. May not be NULL or
* empty.
*
* Return:
* Returns the value stored at the top of the stack.
*/
void* stack_top(struct stack* stack);
/*
* Removes the top element from a stack and returns its value.
*
* Params:
* stack - the stack from which to pop a value. May not be NULL or empty.
*
* Return:
* Returns the value stored at the top of the stack before that value is
* popped.
*/
void* stack_pop(struct stack* stack);
#endif