-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.h
143 lines (141 loc) · 2.74 KB
/
Stack.h
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef Stack_h
#define Stack_h
#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 displayings(stack *top){
if(top->next!=NULL){
displayings(top->next);
}
printf("%c ",top->val);
}
void display(stack *top){
if(top == NULL){
printf("Stack Empty\n");
return;
}
while(top!=NULL){
printf("%c ",top->val);
top = top->next;
}
}
void displayIs(stack *top){
if(top == NULL){
printf("Stack Empty\n");
return;
}
while(top!=NULL){
printf("%d ",top->data);
top = top->next;
}
}
int isFulls(){
stack *check;
check = (stack*)malloc(sizeof(stack));
if(check == NULL)
return 1;
return 0;
}
int isEmptys(stack *top){
if(top == NULL)
return 1;
return 0;
}
void pushing(stack **top, char c){
stack *temp = *top, *link;
if(!isFulls()){
link = (stack*)malloc(sizeof(stack));
link->val = c;
if(temp == NULL){
*top = link;
link->next = NULL;
}
else{
link->next = temp;
*top = link;
}
}
}
void pushI(stack **top, int c){
stack *temp = *top, *link;
if(!isFulls()){
link = (stack*)malloc(sizeof(stack));
link->data = c;
if(temp == NULL){
*top = link;
link->next = NULL;
}
else{
link->next = temp;
*top = link;
}
}
}
void push(stack **top){
char i;
stack *temp = *top, *link;
if(!isFulls()){
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 c;
if(top == NULL)
printf("Stack Empty\n");
else{
temp = *top;
c = temp->val;
(*top) = (*top)->next;
free(temp);
}
return c;
}
int popI(stack **top){
stack *temp;
int c;
if(top == NULL)
printf("Stack Empty\n");
else{
temp = *top;
c = temp->data;
(*top) = (*top)->next;
free(temp);
}
return c;
}
#endif