-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack-in-circular-linked-list.cpp
97 lines (86 loc) · 1.98 KB
/
stack-in-circular-linked-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
90
91
92
93
94
95
96
97
#include <iostream>
#include <stdio.h>
#define MAX 3
using namespace std;
struct mahasiswa {
int data[MAX];
string nama[MAX];
int front;
mahasiswa *next;
}mhs;
mahasiswa *head = NULL, *tail = NULL, *baru, *help, *deleteNode;
void inisialisasi () {
mhs.front = -1;
}
bool isEmpty () {
return mhs.front == -1;
}
bool isFull () {
return mhs.front == MAX - 1;
}
void push () {
if(isFull()){
printf("DATA PENUH");
} else {
baru = new mahasiswa;
baru -> next = baru;
mhs.front++;
printf("DATA : "); cin >> baru -> data[mhs.front];
printf("NAMA : "); cin >> baru -> nama[mhs.front];
if(head == NULL) {
head = baru;
tail = baru;
} else {
tail -> next = baru;
baru -> next = head;
tail = baru;
}
}
}
void pop () {
if(isEmpty()){
printf("DATA KOSONG");
} else {
help = head;
deleteNode = tail;
while (help -> next != tail){
help = help -> next;
}
tail = help;
tail -> next = head;
delete deleteNode;
mhs.front--;
}
}
void view () {
if (isEmpty()){
printf("DATA KOSONG GAN");
} else {
help = head;
int i = 0;
do {
cout << " <- DATA : "<< help -> data[i] << " NAMA : " << help -> nama[i];
i++;
help = help -> next;
}while (help != head);
}
}
main () {
bool exit = false;
int chooseMenu;
inisialisasi();
do {
printf("\n1. PUSH MEONG\n2. POP MIE\n3. VIEW\nCHOOSE : "); cin >> chooseMenu;
switch(chooseMenu){
case 1:
push();
break;
case 2:
pop ();
break;
case 3:
view ();
break;
}
} while (exit == false);
}