Selasa, 26 Mei 2009 |
Double LinkedList |
?html> ?head> ?title>Struktur Data Linked List?/title> ?/head> ?body> ?script language = "JavaScript"> ?!--
function LinkedList() { this._panjang = 0; this._kepala = null; }
LinkedList.prototype = { constructor: LinkedList,
//Membuat Metode untuk Menambah Data Kedalam List Tambah: function (data) { //Membuat Node List var node = {data: data, next: null}, NodeTanda;
//Periksa Isi List if (this._kepala === null) { this._kepala = node; } else { NodeTanda = this._kepala; while (NodeTanda.next) { NodeTanda = NodeTanda.next; } NodeTanda.next = node; } this._panjang++ },
//Membuat metode Untuk Menunjuk Item Data Item: function (index) { if (index > -1 && index ? this._panjang) { var NodeTanda = this._kepala, i = 0; while (i++ ? index) { NodeTanda = NodeTanda.next; } return NodeTanda.data; } else { return null; } },
//Membuat metode Untuk Membuang Elemen List Buang: function (index) { if (index > -1 && index ? this._panjang) { var NodeTanda = this._kepala, previous, i = 0; if (index === 0) { this._kepala = NodeTanda.next; } else { while (i++ ? index) { previous = NodeTanda; NodeTanda = NodeTanda.next; }
previous.next =NodeTanda.next; } this._panjang--; return NodeTanda.data; } else { return null; } },
//Membuat metode Untuk Mengetahui Jumlah Elemen List Ukuran: function() { return this._panjang; },
//Membuat metode Untuk Membentuk Array toArray: function() { var result = [], NodeTanda = this._kepala;
while (NodeTanda) { result.push (NodeTanda.data); NodeTanda = NodeTanda.next; } return result; },
//Membuat metode Untuk Konversi ke String toString: function() { return this.toArray().toString(); }
} var list = new LinkedList ();
list.Tambah("Teknik Informatika"); list.Tambah("Teknik Komputer"); list.Tambah("Komputerisasi Akuntansi"); list.Tambah("Komputer Networking");
document.write("Isi Linked List ?br>"); document.write("--------------- ?br>"); for (i=0; i?4; i++) { document.write(list.Item(i) + "?br>"); } document.write("--------------- ?br>");
alert("Isi Linked List Awal =" +list.Item(0)); alert("Item 1 Pada Linked List dibuang, Yaitu =" +list.Item(1)); list.Buang(1);
document.write("Isi Linked List Terakhir ?br>"); document.write("---------------- ?br>"); for (i=0; i?4; i++) { document.write(list.Item(i) + "?br>"); } document.write("---------------- ?br>");
//--> ?/script> ?/body> ?/html> |
posted by Abah Kemod,,, @ 20.05  |
|
|
|
About Me |
![]()
Name: Abah Kemod,,,
Home:
About Me:
See my complete profile
|
Previous Post |
|
Archives |
|
Sidebar Section |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem, consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem. Fusce aliquam nunc vitae purus. |
Links |
|
 |
|
Thanks for the always useful information. This is great information to help peoples and nice article written by writer. CnX Player is a powerful & efficient 4K ultra HD enabled video player for Windows 10 PC & Tablet, Android and iOS – iPhone & iPad.
Download Media Player for Windows 10 - Microsoft Store
Download Video Player for Android from Google Play
Download Video Player for iPhone/iPad from Apple App Store