-
Notifications
You must be signed in to change notification settings - Fork 2
/
stack.c
50 lines (45 loc) · 998 Bytes
/
stack.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
/*
BATCH NO. 27
Mayank Agarwal (2014A7PS111P)
Karan Deep Batra(2014A7PS160P)
*/
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
#include "ntort.h"
#include "token.h"
void insertstack(stack* st, ntort* ntortinfo, tokeninfo* tokinfo)
{
stacknode* newelem = (stacknode*)malloc(sizeof(stacknode));
newelem->ntortinfo = makentortnode(ntortinfo->nt, ntortinfo->val, ntortinfo->str);
newelem->tokinfo = tokinfo;
// ntort* newelem = makentortnode(node->nt, node->val, node->str);
newelem->next = st->top;
newelem->child = NULL;
newelem->sibling = NULL;
newelem->nptr = NULL;
newelem->idst = NULL;
st->top = newelem;
return;
}
stacknode* popstack(stack* st)
{
if(st->top == NULL)
return NULL;
stacknode* topelem = st->top;
st->top = st->top->next;
// topelem->next = NULL;
return topelem;
}
stacknode* topstack(stack* st)
{
if(st->top == NULL)
return NULL;
return st->top;
}
stack* makestack()
{
stack* st = (stack*)malloc(sizeof(stack));
st->top = NULL;
return st;
}