-
Notifications
You must be signed in to change notification settings - Fork 0
/
Double Link List.cpp
145 lines (132 loc) · 2.78 KB
/
Double Link 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
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
144
145
#include <iostream>
using namespace std;
typedef struct node
{
long data;
node* next;
node* prev;
};
node* head;
node* tail;
node* print;
node* del;
node* entry;
void inisialisasi()
{
head = NULL;
tail = NULL;
}
int isEmpty()
{
if(head == NULL)
return 1;
else
return 0;
}
void input(int *dta)
{
entry = new node;
entry->data = *dta;
entry->next = NULL;
entry->prev = NULL;
if(isEmpty()==1)
{
head = entry;
head->next = NULL;
head->prev = NULL;
tail=head;
}
else
{
tail->next = entry;
entry->prev = tail;
tail = entry;
}
}
void hapus()
{
int simpan;
if(head!=NULL)
{
if(head->next != NULL)
{
del=head;
simpan = head->data;
cout<<"\n"<<simpan<<"dihapus"<<endl;
head = head->next;
head->prev = NULL;
delete del;
}
else
{
simpan = head->data;
cout<<"\n"<<simpan<<"dihapus"<<endl;
head = NULL;
}
}
else
cout<<"\nTidak dapat menghapus karena link list kosong"<<endl;
}
void cetak()
{
print = head;
if(head!=NULL)
{
while(print!=NULL)
{
cout<<"\n\t"<<print->data;
print = print->next;
}
}
else
cout<<"\nLink list tidak memiliki data"<<endl;
}
void menu()
{
char pilih, ulang;
int data;
do
{
system("CLS");
menu :
cout<<"PROGRAM DOUBLE LINK LIST"<<endl;
cout<<"-------------------------------"<<endl;
cout<<"Menu: \n";
cout<<"1. Masukan ata\n";
cout<<"2. Hapus Data\n";
cout<<"3. Cetak Data\n";
cout<<"4. Keluar\n";
cout<<"Masukan pilihan : \n";
cin>>pilih;
switch(pilih)
{
case '1' :
cout<<"\nMasukan Data : ";
cin>>data;
input(&data);
cout<<"\n"<<data<<" ditambahkan"<<endl;
break;
case '2' :
hapus();
break;
case '3' :
cetak();
break;
case '4' :
cout<<"\nTerima kasih "<<endl;
exit;
break;
default :
cout<<"\nPilih Kembali"<<endl;
goto menu;
}
cout<<"\nKembali menuju menu? (y/n)";
cin>>ulang;
}while(ulang=='y' || ulang =='Y');
}
int main()
{
inisialisasi();
menu();
return 0 ;
}