-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
48 lines (26 loc) · 813 Bytes
/
stack.c
File metadata and controls
48 lines (26 loc) · 813 Bytes
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
/*******************************************/
/* */
/* stack.c */
/* */
/*******************************************/
#include "stack.h"
#define current_stacksize( p_S ) ( p_S -> top - p_S -> base)
status init_stack( stack *p_S ) {
p_S -> top = p_S -> base ;
return OK ;
}
bool empty_stack( stack *p_S ) {
return ( p_S -> top == p_S -> base ) ? TRUE : FALSE ;
}
status push( stack *p_S, char c ) {
if ( current_stacksize( p_S ) == MAXSTACKSIZE ) return ERROR ;
p_S -> top ++ ;
*p_S -> top = c ;
return OK ;
}
status pop( stack *p_S, char *p_c ) {
if( empty_stack( p_S ) == TRUE ) return ERROR ;
*p_c = *p_S -> top ;
p_S -> top-- ;
return OK ;
}