-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
40 lines (33 loc) · 815 Bytes
/
Copy pathstack.c
File metadata and controls
40 lines (33 loc) · 815 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
#include <stdio.h>
#include <ctype.h>
#define MAX_LENGTH 100
#define EMPTY -1
#define FULL (MAX_LENGTH -1)
typedef struct {char s[MAX_LENGTH]; int top;} stack;
void reset(stack *stk) {stk->top = EMPTY;}
void push(stack *stk, char c)
{
stk->top++;
stk->s[stk->top] = c;
}
char pop(stack *stk) {return (stk->s[stk->top--]);}
char top(const stack *stk) {return (stk->s[stk->top]);}
int is_empty(const stack *stk) {return (stk->top == EMPTY);}
int is_full(const stack *stk) {return (stk->top == FULL);}
int main(void)
{
stack test_stack;
char *s = "test string";
reset(&test_stack);
int i = 0;
while (s[i] != '\0')
{
push(&test_stack, s[i++]);
}
while (!is_empty(&test_stack))
{
printf("%c", pop(&test_stack));
}
printf("\n\n");
return 0;
}