-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlistStack.c~
73 lines (73 loc) · 1.54 KB
/
linkedlistStack.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
61
62
63
64
65
66
67
68
69
70
71
72
73
//BATCH 12
//TEAM MEMBERS-NIKITA BHALLA-2011A7PS122P
//POOJA GARG-2011A7PS056P
/*#ifndef _STDIO_H
#define _STDIO_H*/
#include<stdio.h>
//#endif
#ifndef _STDLIB_H
#define _STDLIB_H
#include<stdlib.h>
#endif
#ifndef _LINKEDLISTSTACKDEF_H
#define _LINKEDLISTSTACKDEF_H
#include"linkedlistStackDef.h"
#endif
linkedlistStack* create(){
linkedlistStack* s=(linkedlistStack*)malloc(sizeof(linkedlistStack));
if(!s) return NULL;
s->count=0;
s->top=NULL;
return s;
}
void push(parseTreeNode* value,linkedlistStack* s){
node* n=(node*)malloc(sizeof(node));
n->value=value;
n->next=s->top;
s->top=n;
s->count++;
}
parseTreeNode* pop(linkedlistStack* s){
if(s==NULL) {printf("bogus"); return NULL;}
if(s->top==NULL) {printf("2"); return NULL;}
else{
//printf("3");
node* tmp=s->top;
parseTreeNode* temp=tmp->value;
s->top=tmp->next;
s->count--;
//free(tmp);
return temp;
}
}
parseTreeNode* top(linkedlistStack* s){
if(s->top==NULL) return NULL;
else{
return s->top->value;}
}
void displayStack(linkedlistStack* st){
linkedlistStack* s=st;
if(s){
node* tmp;
tmp=s->top;
while(tmp!=NULL){
if(tmp->value->value.isLeafNode){
printf("Leaf:%d\n",tmp->value->value.p.name.tokenIndex);}
else{printf("NT:%d\n",tmp->value->value.p.NonTerminalSymbol);}
tmp=tmp->next;
}//end of while
}//end of if
printf("Displayed the stack");
}
void deleteStack(linkedlistStack* s){
if(s){
node* tmp;
tmp=s->top;
while(tmp!=NULL){
tmp=s->top;
s->top=s->top->next;
free(tmp);
}//end of while
free(s);
}//end of if
}