-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackUsingLinkedListStarterUpdated.c
82 lines (82 loc) · 1.56 KB
/
StackUsingLinkedListStarterUpdated.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
74
75
76
77
78
79
80
81
82
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
char val;
struct node *next;
}stack;
int top(stack *top){
if(top == NULL)
printf("Stack Empty\n");
else
while(top->next != NULL)
top = top->next;
return top->val;
}
void deleteStack(stack **top){
stack *temp ,*link = *top;
if(*top == NULL)
printf("Stack Empty\n");
while(link!=NULL){
temp = link;
link = link->next;
free(temp);
}
*top = NULL;
}
void display(stack *top){
if(top == NULL){
printf("Stack Empty\n");
return;
}
while(top!=NULL){
printf("%c ",top->val);
top = top->next;
}
}
int isFull(){
stack *check;
check = (stack*)malloc(sizeof(stack));
if(check == NULL)
return 1;
return 0;
}
int isEmpty(stack *top){
if(top == NULL)
return 1;
return 0;
}
void push(stack **top){
char i;
stack *temp = *top, *link;
if(!isFull()){
link = (stack*)malloc(sizeof(stack));
printf("Enter Data: ");
fflush(stdin);
scanf("%c",&link->val);
if(temp == NULL){
*top = link;
link->next = NULL;
}
else{
link->next = temp;
*top = link;
}
}
}
char pop(stack **top){
stack *temp;
char i;
if(top == NULL)
printf("Stack Empty\n");
else{
temp = *top;
(*top) = (*top)->next;
free(temp);
}
return i;
}
int main(){
//Enter functions to test their compatibility
return 0;
}