forked from fgrandoinf/centrality-measures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.h
80 lines (67 loc) · 2.25 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
71
72
73
74
75
76
77
78
79
80
#ifndef _STACK_H
#define _STACK_H
/*
* Type: stackElement
* -------------------
* This is the type of the objects entered in the stack.
* Edit it to change the type of things to be placed in
* the stack.
*/
typedef int stackElement;
/*
* Type: stack
* --------------
* This is the type for a stack, i.e., it is a type that
* holds the information necessary to keep track of a stack.
* It has a pointer `contents' to a dynamically-allocated
* array (used to hold the contents of the stack), an integer
* `maxSize' that holds the size of this array (i.e., the
* maximum number of things that can be held in the stack),
* and another integer `top,' which stores the array index of
* the element at the top of the stack.
*/
typedef struct {
stackElement *contents;
int maxSize;
int top;
} stack;
/*
* Function: StackInit
* Usage: StackInit(&stack, maxSize);
* -------------------------
* A new stack variable is initialized. The initialized
* stack is made empty. MaxSize is used to determine the
* maximum number of character that can be held in the
* stack.
*/
void StackInit(stack *stackP, int maxSize);
/* Function: StackDestroy
* Usage: StackDestroy(&stack);
* -----------------------
* This function frees all memory associated with the stack.
* The `stack' variable may not be used again unless
* StackInit(&stack, maxSize) is first called on the stack.
*/
void StackDestroy(stack *stackP);
/*
* Functions: StackPush, StackPop
* Usage: StackPush(&stack, element); element = StackPop(&stack);
* --------------------------------------------
* These are the fundamental stack operations that add an element to
* the top of the stack and remove an element from the top of the stack.
* A call to StackPop on an empty stack or to StackPush on a full stack
* is an error. Make use of StackIsEmpty()/StackIsFull() (see below)
* to avoid these errors.
*/
void StackPush(stack *stackP, stackElement element);
stackElement StackPop(stack *stackP);
/*
* Functions: StackIsEmpty, StackIsFull
* Usage: if (StackIsEmpty(&stack)) ...
* -----------------------------------
* These return a true value if the stack is empty
* or full (respectively).
*/
int StackIsEmpty(stack *stackP);
int StackIsFull(stack *stackP);
#endif /* not defined _STACK_H */