forked from syamcode/PecimenGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.cpp
89 lines (78 loc) · 1.41 KB
/
list.cpp
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
#include "includes/list.h"
void CreateStack(Stack *s) {
Top(*s) = Nil;
}
address Alokasi(infotype n) {
address N;
N = (address) malloc (sizeof(node));
if (N!=Nil) {
Info(N) = n;
Next(N) = Nil;
}
return N;
}
void Push(Stack *s, infotype n) {
address N = Alokasi(n);
if (N!=Nil) {
Next(N) = Top(*s);
Top(*s) = N;
}
else {
printf("Overflow\n");
}
}
infotype Pop(Stack *s) {
address del;
infotype info;
del = Top(*s);
if (del!=Nil) {
info = Info(del);
Top(*s) = Next(del);
free(del);
}
else {
info = -1; //Underflow
}
return info;
}
void CreateQueue(Queue *Q) {
Front(*Q) = Nil;
Rear(*Q) = Nil;
}
void EnQueue(Queue *Q, infotype n) {
address N = Alokasi(n);
if (N!=Nil) {
if (Rear(*Q)!=Nil) {
Next(Rear(*Q)) = N;
}
else {
Front(*Q) = N;
}
Rear(*Q) = N;
}
else {
printf("Overflow\n");
}
}
infotype DeQueue(Queue *Q) {
address del;
infotype info;
del = Front(*Q);
if (del!=Nil) {
info = Info(del);
if (Next(del)==Nil) {
Rear(*Q) = Nil;
}
Front(*Q) = Next(del);
free(del);
}
else {
info = -1; //Underflow
}
return info;
}
void EmptyStack(Stack *s) {
while (Top(*s) != Nil) {
Pop(s);
}
}