LINKLIST
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <alloc.h>
int pil;
void pilih();
void create();
void insert();
void hapus_depan();
void print();
struct node
{
char jabatan[10], nama[45], gaji[11];
struct node *next;
} *baru, *head=NULL, *akhir=NULL,*hapus,*bantu;
int main()
{
do
{
clrscr();
cout<<" DAFTAR MENU SINGLE
LINKEDLIST"<<endl;
cout<<"1.
INSERT"<<endl;
cout<<"2.
DELETE"<<endl;
cout<<"3. PRINT"<<endl;
cout<<"4.
FINISH"<<endl;
cout<<"Pilihan Anda : ";
cin>>pil;
pilih();
} while(pil!=4);
return 0;
}
void pilih()
{
if(pil==1)
insert();
else if(pil==2)
hapus_depan();
else
if(pil==3)
print();
else
cout<<"selesai";
}
void create()
{
baru=(node*)malloc(sizeof(struct node));
cout<<"INPUT NAMA LENGKAP : ";cin>>baru->nama;
cout<<"JABATAN : ";cin>>baru->jabatan;
cout<<"GAJI/bln :
";cin>>baru->gaji;
baru->next=NULL;
}
void insert()
{
create();
if(head==NULL)
{
head=baru;
akhir=baru;
akhir->next=NULL;
}
else
{
head->next=head;
head=baru;
}
cout<<endl<<endl;
clrscr();
print();
}
void hapus_depan()
{
if (head==NULL)
cout<<"Kosong";
else
{
hapus=head;
head=head->next;
free(hapus);
}
cout<<endl<<endl;
clrscr();
print();
}
void print()
{
if (head==NULL)
cout<<"Kosong";
else
{
bantu=head;
while(bantu!=NULL)
{
cout<<" NAMA LENGKAP :
"<<bantu->nama<<endl;
cout<<" JABATAN : "<<bantu->jabatan<<endl;
cout<<" GAJI/bln :
"<<bantu->gaji<<endl;
bantu=bantu->next;
}
}
getch();
}
No comments:
Post a Comment