CONTOH CODING LINKED LIST MENGGUNAKAN BORLAND C++
#include<stdlib.h>
#include<conio.h>
#include<iostream.h>
struct simpul
{
int angka;
struct simpul*berikut;
} ;
struct simpul *awal=NULL;
int bil;
void tambah_list_didepan(int info)
{
struct simpul *baru;
baru=(struct simpul *)malloc(sizeof(struct simpul));
baru->angka=info;
baru->berikut=awal;
awal=baru;
}
void isi_list()
{
int jml;
cout<<"\nJumlah Data : ";cin>>jml;
cout<<"+-------------------------+\n";
for(int b=0;b<jml;b++)
{
cout<<"Masukkan Data ke-"<<(b+1)<<" : ";cin>>bil;
tambah_list_didepan(bil);
}
cout<<"+-------------------------+\n";
}
void tampil_list()
{
struct simpul* baca;
baca=awal;
cout<<"\nBilangan yang dibaca : ";
while(baca!=NULL)
{
cout<<baca->angka<<" -> ";
baca=baca->berikut;
}
cout<<"NULL\n";
}
main()
{
char pilih;
int a=0;
cout<<"\n SINGLE LINKED LIST "<<endl;
cout<<"+-------------------------+\n";
cout<<"Menu : "<<endl;
cout<<"1. Input data"<<endl;
cout<<"2. Cetak Data"<<endl;
cout<<"3. Exit"<<endl;
while(a<(a+1))
{
cout<<"Masukkan pilihan Anda : ";cin>>pilih;
switch(pilih)
{
case '1' : isi_list(); break;
case '2' : tampil_list(); break;
case '3' : exit(0); break;
default : cout<<"\n* Pilih Ulang *"<<endl;
}
cout<<endl;
a++;
}
getch();
}