disusun oleh :
Yus Hariadi
08.11.2104
08.11.2090
Ferdinanta Tarigan
08.11.2142
KATA PENGANTAR
Dengan mengucapkan puja dan puji syukur kehadirat Allah SWT
yang telah memberikan rahmat dan hidayah-Nya sehingga makalah
STRUKTUR DATA (Double Linked List Circular) ini telah kami selesaikan
tepat pada waktunya.
Makalah Double Linked List Circular dibuat sebagai bahan materi
Struktur Data. Makalah ini memberikan sedikit gambaran tentang program
link list, sehingga makalah ini dapat dijadikan sebagai referensi untuk kita.
Kami sadar bahwa buku ini masih jauh dari sempurna sehingga
saran dan kritik pembaca yang sifatnya membangun sangat kami
harapkan demi penyempurnaan makalah ini. Terima kasih kami ucapkan
kepada teman sekelompok kami yang telah membantu dalam pengerjaan
makalah ini.
Semoga makalah ini dapat bermanfaat dan berguna bagi kita
semua.
DAFTAR ISI
Halaman
Cover
.
Kata
Pengantar
..
Daftar
Isi..
..
BAB
I.
PEMBAHASAN..
.
1. Pengertian
Double
Linked
List
Circular.
2. Illustrasi
Double
Linked
4
List
Circular..
5
3. Deklarasi dan Node Baru DLLC.
.
4. Dllc
dengan
5
Head.
...
5
5. Dllc dengan Head dan Tail.
...
6. Contoh Program.
..
9
10
BAB II.KESIMPULAN...
..14
Refrensi.
.. 15
BAB I. PEMBAHASAN
DOUBLE LINKED LIST CIRCULAR (DLLC)
1. PENGERTIAN
Double
lihat pada
Double Linked List Circular adalah linked list dengan menggunakan
pointer, dimana setiap node memiliki 3 field, yaitu 1 field pointer yang
menunjuk
pointer
berikutnya
(next),
field
menunjuk
pointer
sebelumnya (prev), serta sebuah field yang berisi data untuk node
tersebut.
Double Linked List Circular pointer next dan prev nya menunjuk ke
dirinya sendiri secara circular.
2. ILUSTRASI DLLC
Setiap node pada linked list mempunyai field yang berisi data dan
pointer ke node berikutnya & ke node sebelumnya
Untuk pembentukan node baru, mulanya pointer next dan prev akan
menunjuk ke dirinya sendiri.
Jika sudah lebih dari satu node, maka pointer prev akan menunjuk ke
node sebelumnya, dan pointer next akan menunjuk ke node
sesudahnya. Lihat gambar 1.2
3. DEKLARASI DAN NODE BARU DLLC
Deklarasi node
typedef struct TNode{
int data;
STRUKTUR DATA |Double Linked List Circular
TNode *next;
Tnode *prev;
};
Pembentukan node baru
Digunakan keyword new yang berarti mempersiapkan sebuah node
baru berserta alokasi memorinya.
TNode *baru;
baru = new TNode;
baru->data = databaru;
baru->next = baru;
baru->prev = baru;
4. DLLC dengan HEAD
Dibutuhkan satu buah variabel pointer: head
Head akan selalu menunjuk pada node pertama
akan
tetap
selalu
menjadi
data
terdepan.
Untuk
if(isEmpty()==1){
head=baru;
head->next = head;
head->prev = head;
}
else {
bantu = head->prev;
baru->next = head;
head->prev = baru;
head = baru;
head->prev = bantu;
bantu->next = head;
}
cout<<"Data masuk\n";
}
Fungsi Penambahan data di belakang
void insertBelakang (int databaru){
TNode *baru,*bantu;
baru = new TNode;
baru->data = databaru;
baru->next = baru;
baru->prev = baru;
if(isEmpty()==1){
head=baru;
head->next = head;
head->prev = head;
}
else {
bantu=head->prev;
bantu->next = baru;
baru->prev = bantu;
baru->next = head;
head->prev = baru;
}
STRUKTUR DATA |Double Linked List Circular
cout<<"Data masuk\n";
}
Function untuk menampilkan isi linked list
void tampil(){
TNode *bantu;
bantu = head;
if(isEmpty()==0){
do{
cout<<bantu->data<<" ";
bantu=bantu->next;
}while(bantu!=head);
cout<<endl;
} else cout<<"Masih kosong\n";
}
Function untuk menghapus node terdepan
void hapusDepan (){
TNode *hapus,*bantu;
int d;
if (isEmpty()==0){
if(head->next != head){
hapus = head;
d = hapus->data;
bantu = head->prev;
head = head->next;
bantu->next = head;
head->prev = bantu;
delete hapus;
} else {
d = head->data;
head = NULL;
}
cout<<d<<" terhapus\n";
} else cout<<"Masih kosong\n";
}
Function untuk menghapus node terbelakang
void hapusBelakang(){
TNode *hapus,*bantu;
int d;
if (isEmpty()==0){
if(head->next != head){
bantu = head;
while(bantu->next->next != head){
STRUKTUR DATA |Double Linked List Circular
bantu = bantu->next;
}
hapus = bantu->next;
d = hapus->data;
bantu->next = head;
delete hapus;
} else {
d = head->data;
head = NULL;
}
cout<<d<<" terhapus\n";
} else cout<<"Masih kosong\n";
}
6. CONTOH PROGRAM
#include<iostream.h>
#include<conio.h>
class cirdlink
{
struct node
{
int data;
node *rnext;
node *lnext;
}*new1,*head,*tail,*ptr,*temp;
public:
cirdlink()
{
head=tail=NULL;
}
void
void
void
void
creation();
insertion();
deletion();
display();
};
void cirdlink :: creation()
{
if(head==NULL)
{
new1=new node[sizeof(node)];
new1->rnext=NULL;
new1->lnext=NULL;
cout<<"enter student number:";
cin>>new1->data;
head=new1;
tail=new1;
head->rnext=tail;
head->lnext=tail;
tail->rnext=head;
tail->lnext=head;
}
else
cout<<"creation done only once:";
}
void cirdlink :: insertion()
{
int i,pos;
new1=new node[sizeof(node)];
new1->rnext=NULL;
new1->lnext=NULL;
cout<<"enter student number:";
cin>>new1->data;
cout<<"enter position you want to insert:";
cin>>pos;
if(pos==1)
{
new1->rnext=head;
head=new1;
tail->lnext=head;
tail->rnext=head;
head->lnext=tail;
}
else
{
i=1;
temp=head;
while(i < pos-1 && temp->rnext!=tail)
{
i++;
temp=temp->rnext;
}
if(temp->rnext==tail)
{
new1->rnext=tail->rnext;
tail->rnext=new1;
new1->lnext=tail;
tail=new1;
head->lnext=tail;
}
else
{
new1->rnext=temp->rnext;
new1->lnext=temp;
temp->rnext=new1;
new1->rnext->lnext=new1;
}
}
}
void
{
cirdlink :: deletion()
int pos,i;
cout<<"Enter Position you want to Delete:";
cin>>pos;
if(pos==1 && head!=tail)
{
ptr=head;
head=head->rnext;
head->lnext=tail;
tail->rnext=head;
delete ptr;
}
else
{
i=1;
temp=head;
while(i < pos-1 && temp->rnext!=tail)
{
i++;
temp=temp->rnext;
}
if(temp->rnext!=tail)
{
ptr=temp->rnext;
temp->rnext=ptr->rnext;
ptr->rnext->lnext=ptr->lnext;
delete ptr;
}
else
{
if(temp->rnext==tail && head!=tail)
{
ptr=tail;
tail=temp;
tail->rnext=head;
head->lnext=tail;
delete ptr;
}
else
{
head=NULL;
tail=NULL;
delete head;
delete tail;
}
}
}
}
void cirdlink::display()
{
int ch;
cout<<"1.forward\n2.backward:";
cout<<"\nEnter your choice<1/2>:";
cin>>ch;
switch(ch)
{
case 1: if(head!=NULL)
{
temp=head;
while(temp!=tail)
{
cout<<temp->data<<"
temp=temp->rnext;
}
if(temp==tail)
cout<<temp->data;
}
break;
case 2 :
if(tail!=NULL)
{
temp=tail;
while(temp!=head)
{
cout<<temp->data<<"
temp=temp->lnext;
}
if(temp==head)
cout<<temp->data;
}
break;
void main()
{
cirdlink c1;
int ch;
";
";
char op;
do
{
clrscr();
cout<<"----------Menu------------";
cout<<"\n1.Creation\n2.Insertion\n3.Deletion\n4.Display";
cout<<"\nEnter Your choice:";
cin>>ch;
switch(ch)
{
case 1 :
c1.creation();
break;
case 2 :
c1.insertion();
break;
case 3 :
c1.deletion();
break;
case 4 :
c1.display();
break;
}
cout<<"\nDo you want to continue <Y/N>:";
cin>>op;
}while(op=='y' || op=='Y');
getch();
}
IsEmpty
Find First : Fungsi ini mencari elemen pertama dari linked list
Find Next : Fungsi ini mencari elemen sesudah elemen yang ditunjuk
now.
Retrieve
Update
Delete Now : Fungsi ini menghapus elemen yang ditunjuk oleh now.
Jika yang dihapus adalah elemen pertama dari linked list
(head), head akan berpindah ke elemen berikut.
Delete Head : Fungsi ini menghapus elemen yang ditunjuk head.
Head berpindah ke elemen sesudahnya.
Clear
REFERENSI
www.google.com Double Linked List Circular
Rachmat,Antonius C, S.Kom
Wikipedia
http://answer.yahoo.com/doublelinklistcircularscript/