-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
executable file
·37 lines (34 loc) · 813 Bytes
/
stack.c
File metadata and controls
executable file
·37 lines (34 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
#include "common.h"
/*************************************************************
*This file implements stack data struct with list.
*************************************************************/
void stack_init(t_stack *st)
{
*st = NIL;
}
boolean stack_is_empty(t_stack *st)
{
return *st == NIL;
}
void stack_push(t_stack *st, cellpoint ele)
{
*st = cons(ele, *st);
}
cellpoint stack_pop(t_stack *st)
{
if (stack_is_empty(st)){
perror("Error: the stack is empty. --STACK_POP\n");
error_handler();
}
cellpoint top = car(*st);
*st = cdr(*st);
return top;
}
cellpoint stack_top(t_stack *st)
{
if (stack_is_empty(st)){
perror("Error: the stack is empty. --STACK_TOP\n");
error_handler();
}
return car(*st);
}