Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

LIST CODE LINKED LIST

#include <conio.h> cout<<bantu->data<<" ";


#include <iostream.h> bantu=bantu->next;
}
struct TNode cout<<endl;
{ }
int data; else cout<<"Data Masih kosong\n";
TNode *next; }
};
void hapusdepan()
TNode *head; {
TNode *hapus;
void init() int d;
{ if (isempty()==0)
head=NULL; {
} if (head->next !=NULL)
{
int isempty() hapus=head;
{ d=hapus->data;
if(head==NULL) head=head->next;
return 1; delete hapus;
else return 0; }
} else
{
void insertdepan (int databaru) d=head->data;
{ head=NULL;
TNode *baru; }
baru= new TNode; cout<<d<<" dihapus\n";
baru->data =databaru; }
baru->next=NULL; else cout<<"masih kosong\n";
}
if (isempty()==1)
{ void main()
head=baru; {
head->next=NULL; int pil;
} int databaru;
else do
{ {
baru->next=head; clrscr();
head=baru; cout<<"Program Linked list untuk data
} angka\n"<<endl;
cout<<"Ok Data Masuk dan tersimpan\n"; cout<<"1.Insert Depan"<<endl;
} cout<<"2.Tampil"<<endl;
cout<<"3.Hapus"<<endl;
void tampil() cout<<"4.Exit"<<endl;
{ cout<<"\npilihan anda= ";cin>>pil;
TNode *bantu; switch(pil)
bantu=head; {
if(isempty()==0)
{
while (bantu!=NULL)
{
{
case 1:
cout<<endl;
cout<<"silahkan masukan data:
";cin>>databaru;
insertdepan (databaru);
break;
}
{
case 2:
cout<<endl;
tampil();
break;
}
{
case 3:
cout<<endl;
hapusdepan();
break;
}
}
getch();
}while (pil!=4);
}

You might also like