-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
38 lines (37 loc) · 938 Bytes
/
stack.c
File metadata and controls
38 lines (37 loc) · 938 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
#include "stack.h"
// Initialization
void initOp( struct operatorStack* a ) {
a->top = 0;
}
// Initialization
void initData( struct dataStack* a ) {
a->top = 0;
}
// Pushes an operator b into the stack
void pushOp( struct operatorStack* a, char b ) {
a->op[a->top++] = b;
}
// Pop the top operator element
char popOp( struct operatorStack* a ) {
return (*a).op[--(*a).top];
}
// Return the top operator element
char topOp( struct operatorStack* a ) {
return a->op[a->top - 1];
}
// Push a number (or an operator) into stack.
void pushData( struct dataStack* a, long double b ) {
a->data[a->top++] = b;
}
// Pop the top data element
long double popData( struct dataStack* a ) {
return a->data[--a->top];
}
// Determine whether the stack is empty.
int emptyOp( struct operatorStack* a ) {
return a->top;
}
// Determine whether the stack is empty.
int emptyData( struct dataStack* a ) {
return a->top;
}