-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackTree.c
60 lines (53 loc) · 1011 Bytes
/
stackTree.c
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
49
50
51
52
53
54
55
56
57
58
59
60
/*
GROUP NUMBER: 45
GROUP MEMBERS:
1. SHAH NEEL KAUSHIK
2. MEHTA AASHAY PINKESH
3. RANADE SHUBHANKAR PRASAD
*/
#include "stackTree.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(StackNode stNode, Stack st){
//insert at front
stNode->next = st->head;
st->head = stNode;
st->size++;
return st;
}
StackNode createNode(AttNode grammar_node)
{
StackNode stNode = (StackNode) malloc(sizeof(struct stackNode));
stNode->grammar_node = grammar_node;
stNode->next=NULL;
stNode->parent=NULL;
stNode->right=NULL;
stNode->child=NULL;
stNode->inh=NULL;
stNode->syn=NULL;
stNode->addr=NULL;
stNode->rule_id = -2;
return stNode;
}
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;
}
StackNode top(Stack st){
if(st->head == NULL)
return NULL;
return st->head;
}