-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linked List Mahasiswa.CPP
90 lines (83 loc) · 1.38 KB
/
Linked List Mahasiswa.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
#include <iostream>
using namespace std;
struct Mhs
{
char NBI[10];
char Nama[50];
int Nilai;
Mhs *Kanan;
};
Mhs *PAwal, *PAkhir ; // Global
int PilihMenu()
{
int Pilih=0;
//while(Pilih <1 || Pilih > 4)
while(!(Pilih>=1 && Pilih <=4))
{
cout<<"MENU UTAMA"<<endl<<endl;
cout<<"1. ENTRY DATA"<<endl;
cout<<"2. DISPLAY DATA"<<endl;
cout<<"3. SELESAI"<<endl<<endl;
cout<<"PILIHAN = ";
cin>>Pilih;
}
return Pilih;
}
void EntryData()
{
Mhs *NodeBaru;
NodeBaru = new Mhs;
cout<<"NBI = ";
gets(NodeBaru->NBI);
cout<<"NAMA = ";
gets(NodeBaru->Nama);
cout<<"NILAI = ";
cin>>NodeBaru->Nilai;
NodeBaru->Kanan=NULL;
if(PAwal==NULL)
{
//Link List Kosong
PAwal=NodeBaru;
PAkhir=NodeBaru;
}
else
{
//Link List Tidak Kosong
PAkhir->Kanan=NodeBaru;
PAkhir = NodeBaru;
}
}
void DisplayData()
{
Mhs *PNode;
PNode=PAwal;
while(PNode !=NULL)
{
cout<<PNode->NBI<<"\t"<<PNode->Nama<<"\t"
<<PNode->Nilai<<endl;
PNode = PNode->Kanan;
}
}
main()
{
int Pilih=0,Indek=0;
PAwal=NULL;
PAkhir=NULL;
while(!(Pilih>=1 && Pilih<=4))
{
Pilih=PilihMenu();
switch(Pilih)
{
case 1:
EntryData();
Pilih=0;
break;
case 2:
DisplayData();
Pilih=0;
break;
case 3:
break;
}
}
}