Professional Documents
Culture Documents
hanNabi
yl
ah
221011402502
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
st
ructMahasi
swa{
st
ri
ngnama;
i
ntni
m;
st
ri
nggender
;
f
loatni
l
ai;
Mahasi
swa*next
;
}
;
Mahasi
swa*head=NULL;
v
oidi
nser
tDat
a(){
st
ri
ngnama,
gender
;
i
ntni
m;
f
loatni
l
ai;
cout<<"
MasukkanNama:
";
ci
n>>nama;
cout<<"
MasukkanNI
M:"
;
ci
n>>ni
m;
cout<<"
MasukkanGender
:";
ci
n>>gender
;
cout<<"
MasukkanNi
l
ai:
";
ci
n>>ni
l
ai;
Mahasi
swa*newMahasi
swa=newMahasi
swa;
newMahasi
swa-
>nama=nama;
newMahasi
swa-
>ni
m =ni
m;
newMahasi
swa-
>gender=gender
;
newMahasi
swa-
>ni
l
ai=ni
l
ai;
i
f(head==NULL){
head=newMahasi
swa;
newMahasi
swa-
>next=head;
}el
se{
Mahasi
swa*t
emp=head;
whi
l
e(t
emp-
>next!
=head){
t
emp=t
emp-
>next
;
t
emp-
>next=newMahasi
swa;
newMahasi
swa-
>next=head;
cout<<"
Dat
aber
hasi
ldi
tambahkan!
"<<endl
;
}
v
oidhapusDat
a(){
i
f(head==NULL){
cout<<"
Linkedl
i
stkosong!
"<<endl
;
r
etur
n;
i
ntni
m;
cout<<"
MasukkanNI
Myangakandi
hapus:
";
ci
n>>ni
m;
Mahasi
swa*cur
rent=head;
Mahasi
swa*pr
evi
ous=NULL;
do{
i
f(cur
rent
->ni
m ==ni
m){
i
f(pr
evi
ous==NULL){
whi
l
e(cur
rent
->next!
=head){
cur
rent=cur
rent
->next
;
cur
rent
->next=head-
>next
;
del
etehead;
head=cur
rent
->next
;
}el
se{
pr
evi
ous-
>next=cur
rent
->next
;
del
etecur
rent
;
cout<<"
Dat
adenganNI
M "<<ni
m <<"ber
hasi
ldi
hapus!
"<<endl
;
r
etur
n;
pr
evi
ous=cur
rent
;
cur
rent=cur
rent
->next
;
}whi
l
e(cur
rent!
=head)
;
cout<<"
Dar
adenganNI
M "<<ni
m <<"
ti
dakdi
temukan!
"<<endl
;
v
oidcet
akDat
a(){
i
f(head==NULL){
cout<<"
Linkedl
i
stkosong!
"<<endl
;
r
etur
n;
Mahasi
swa*t
emp=head;
do{
cout<<"
Nama:
"<<t
emp-
>nama<<endl
;
cout<<"
NIM:
"<<t
emp-
>ni
m <<endl
;
cout<<"
Gender
:"<<t
emp-
>gender<<endl
;
cout<<"
Nil
ai:
"<<t
emp-
>ni
l
ai<<endl
;
cout<<"
==================="<<endl
;
t
emp=t
emp-
>next
;
}whi
l
e(t
emp!
=head)
;
i
ntmai
n()
{
i
ntpi
l
ihan;
do{
cout<<"
CIRCULARLI
NKEDLI
ST"<<endl
;
cout<<"
==================="<<endl
;
cout<<"
1.I
NSERTDATA"<<endl
;
cout<<"
2.HAPUSDATA"<<endl
;
cout<<"
3.CETAKDATA"<<endl
;
cout<<"
4.EXI
T"<<endl
;
cout<<"
Pil
i
han(
1-4)
:";
ci
n>>pi
l
ihan;
swi
tch(
pil
i
han){
case1:
i
nser
tDat
a()
;
br
eak;
case2:
hapusDat
a()
;
br
eak;
case3:
cet
akDat
a()
;
br
eak;
case4:
cout<<"
Progr
am Sel
esai
."<<endl
;
br
eak;
def
aul
t:
cout<<"
Pil
i
hant
idakv
ali
d!"<<endl
;
}whi
l
e(pi
l
ihan!
=4)
;
r
etur
n0;