Welcome To Aloen BloG

Single Linked List Circular

Diposting oleh Unknown | 09.15 | | 0 komentar »

Single Linked List Circular (SLLC) adalah Single Linked List yang pointer nextnya menunjuk pada dirinya sendiri. Jika Single Linked List tersebut terdiri dari beberapa node, maka pointer next pada node terakhir akan menunjuk ke node terdepannya.

Pengertian:
Node : rangkaian beberapa simpul
Single : artinya field pointer-nya hanya satu buah saja dan satu arah.
Linked List : artinya node-node tersebut saling terhubung satu sama lain.
Circular : artinya pointer next-nya akan menunjuk pada dirinya sendiri sehingga berputar

Contoh single linked list:

#include

#include

struct TNode //deklarasi awal LINKED LIST

{

int data;

TNode *next;

};

TNode *head;

void init()

{

head = NULL;

}

int isEmpty()

{

if(head == NULL) return 1;

else return 0;

}

void insertDepan(int databaru)

{

TNode *baru;

baru = new TNode;

baru->data = databaru;

baru->next = NULL;

if(isEmpty()==1)

{

head=baru;

head->next = NULL;

}

else

{

baru->next = head;

head = baru;

}

cout<

cout<<" Data masuk...\n";

getch();

}

void hapusDepan()

{

TNode *hapus;

int d;

if (isEmpty()==0)

{

if(head->next != NULL)

{

hapus = head;

d = hapus->data;

head = head->next;

delete hapus;

}

else

{

d = head->data;

head = NULL;

}

cout<

cout<<" Data "<<<">

}

else

{

cout<

cout<

cout<<" Linked List Masih kosong...\n";

}

getch();

}

void search(int caridata)

{

TNode *bantu;

bantu = head;

int ketemu = 0;

int index=0;

if(isEmpty()==0)

{

while(bantu!=NULL)

{

bantu->data;

if (caridata == bantu->data)

{

cout<

cout<<" Data Ditemukan..."<

cout<<" Index Ke - "<

ketemu = 1;

break;

}

bantu=bantu->next;

index++;

}

cout<

if (ketemu == 0)

cout<<" Data Tidak Ditemukan..."<

cout<

} else cout<<" Linked List Masih kosong...\n";

getch();

}

void tampil()

{

TNode *bantu;

bantu = head;

if(isEmpty()==0)

{

cout<<" Data Linked List"<

cout<<"================================="<

while(bantu!=NULL)

{

cout<<" --> "<data<<" ";

bantu=bantu->next;

}

cout<<" --> NULL";

cout<

} else cout<<" Linked List Masih kosong...\n";

getch();

}

void main()

{

int pil,dataku,cari;

init(); //inisialisasi awal

do

{

clrscr();

cout<<" SINGLE LINKED LIST"<

cout<<"=========================="<

cout<<" 1. Insert List"<

cout<<" 2. Delete Front"<

cout<<" 3. Show Linked List"<

cout<<" 4. Search Data"<

cout<<" 5. Exit"<

cout<<"=========================="<

cout<

cout<<"Pilihan Anda = "; cin>>pil;

switch (pil)

{

case 1 :

cout<

cout<<" Insert Data --> "; cin>>dataku;

insertDepan(dataku);

break;

case 2 :

hapusDepan();

break;

case 3 :

cout<

cout<

tampil();

break;

case 4 :

cout<

cout<<" Data yg Dicari --> "; cin>>cari;

search(cari);

break;

};

}

while (pil != 5);

}

Download program file yang lebih lengkap klik Disini

0 komentar

Followers

Visitor

 

Aloen Pop. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com