-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
64 lines (56 loc) · 1.06 KB
/
Stack.cpp
File metadata and controls
64 lines (56 loc) · 1.06 KB
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
#include "Const.h"
#include "Stack.h"
static int g_Top = -1;
static char g_Stack[STACK_LIMIT] = {0,};
// Overflow...
static int OverflowedWithArgs( int curPos )
{
if(curPos >= STACK_LIMIT)
return TRUE;
return FALSE;
}
// if is Overflow...return 1
// otherwise return 0
// g_Top greater equal(ge) than STACK_LIMIT(256)
int Overflowed( void )
{
if( OverflowedWithArgs( g_Top ) == TRUE )
return TRUE;
return FALSE;
}
// Underflow...
static int UnderflowedWithArgs( int curPos )
{
if( curPos < ZERO )
return TRUE;
return FALSE;
}
// if is Underflow...return 1
// otherwise return 0
// g_Top equal(ge) than -1
int Underflowed( void )
{
if( UnderflowedWithArgs( g_Top ) == TRUE )
return TRUE;
return FALSE;
}
char Push( char bChar )
{
// Check the Overflow...
if( OverflowedWithArgs( g_Top ) == TRUE )
return FALSE;
g_Top++;
g_Stack[g_Top] = bChar;
return bChar;
}
char Pop( void )
{
char bChar;
// Check the Underflow...
if( UnderflowedWithArgs( g_Top ) == TRUE )
return FALSE;
g_Top--;
bChar = g_Stack[g_Top];
g_Stack[g_Top] = 0;
return bChar;
}