-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackarray.h
46 lines (40 loc) · 860 Bytes
/
stackarray.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
#define MAXSTACK 5
#define TRUE 1
#define FALSE 0
typedef struct stack
{
int a[MAXSTACK];
int top;
}S;
// function prototypes
void initStack(S *); // initializing the stack
void push(S *, int, int *); // push an integer to the stack
void pop(S *, int *, int *); // pop an element out of the stack
// function definitions
// initializing the stack
void initStack(S *pStack)
{
pStack->top=-1;
}
// push an integer to the stack
void push(S *pStack,int toPush,int *overflow)
{
if(pStack->top==MAXSTACK-1)
*overflow = TRUE;
else
{
*overflow = FALSE;
pStack->a[++(pStack->top)] = toPush;
}
}
// pop an element out of the stack
void pop(S *pStack,int *popped,int *underflow)
{
if(pStack->top==-1)
*underflow = TRUE;
else
{
*underflow = FALSE;
*popped = pStack->a[(pStack->top)--];
}
}