forked from neolay/HeartMaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.h
48 lines (43 loc) · 768 Bytes
/
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
#pragma once
#include "public.h"
typedef struct
{
Block *base;
Block *top;
int stacksize;
}SqStack;
void initStack(SqStack &S)
{
S.base = (Block*)malloc(STACK_INIT_SIZE * sizeof(Block));
if (!S.base)
return;
S.top = S.base;
S.stacksize = STACK_INIT_SIZE;
}
void push(SqStack &S, Block e)
{
if (S.top - S.base >= S.stacksize)
{
S.base = (Block*)realloc(S.base, (S.stacksize + STACKINCREMENT) * sizeof(Block));
if (!S.base)
return;
S.top = S.base + S.stacksize;
S.stacksize += STACKINCREMENT;
}
*S.top = e;
S.top++;
}
void pop(SqStack &S, Block&e)
{
if (S.top == S.base)
return;
S.top--;
e = *S.top;
}
bool isEmpty(SqStack S)
{
if (S.top == S.base)
return true;
else
return false;
}