-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
41 lines (34 loc) · 680 Bytes
/
stack.c
File metadata and controls
41 lines (34 loc) · 680 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
#include "stack.h"
Stack newStack(){
Stack st = (Stack) malloc(sizeof(struct stack));
st->head = NULL;
st->size = 0;
return st;
}
int isEmpty(Stack st){
return st->head == NULL;
}
Stack push(AttNode grammar_node, Stack st){
StackNode stNode = (StackNode) malloc(sizeof(struct stackNode));
stNode->grammar_node = grammar_node;
//insert at front
stNode->next = st->head;
st->head = stNode;
st->size++;
return st;
}
Stack pop(Stack st){
if(st->head == NULL){
st->size = 0;
return st;
}
StackNode temp = st->head;
st->head = temp->next;
st->size--;
return st;
}
AttNode top(Stack st){
if(st->head == NULL)
return NULL;
return st->head->grammar_node;
}