Sabtu, 30 Mei 2009

Double LinkedList

?html>
?head>?title>Struktur Data Linked List?/title>?/head>
?body>
?script language = "javascript">
?!--

function DoubleLinkedList()
/
this._panjang = 0;
this._kepala = null;
this._ekor = null;
}

DoubleLinkedList.prototype =
/
constructor:DoubleLinkedList,


Tambah: function (data)
/
var node = / data: data, next: null, prev: null };
if (this._panjang == 0)
/
this._kepala = node;
this._ekor = node;
}
else
/
this._ekor.next = node;
node.prev = this._ekor;
this._ekor = node;
}
this._panjang++;
},


ItemList: 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;
}
},

Buang: function (index)
/
if (index > -1 && index ? this._panjang)
/
var NodeTanda = this._kepala, i = 0;
if (index === 0)
/
this._kepala = NodeTanda.next;

if (this._kepala)
/
this._ekor = null;
}
else
/
this._kepala.prev = null;
}
}
else if (index === this._panjang -1)
/
NodeTanda = this._ekor;
this._ekor = NodeTanda.prev;
this._ekor.next = null;
}
else

/
while (i++ ? index)
/
NodeTanda = NodeTanda.next;
}

NodeTanda.prev.next =NodeTanda.next;
}
this._panjang--;
return NodeTanda.data;
}
else
/
return null;
}
},




toString: function()
/
return this.toArray().toString();
}
}
var list = new DoubleLinkedList();

list.Tambah ("Teknik Informatika");
list.Tambah ("Teknik Komputer");
list.Tambah ("Komputerisasi Akuntansi");
list.Tambah ("Computer Networking");

document.write ("Isi LinkedList ?br>");
document.write ("-------------- ?br>");
for (i=0; i?4; i++)
/
document.write(list.ItemList(i) +"?br>");
}
document.write ("-------------- ?br>");

alert("Isi Linked List Awal =" +list.ItemList(0));
alert("Item 1 pada Linked List dibuang, yaitu = "+list.ItemList(1));
list.Buang(1);

document.write ("Isi LinkedList Terakhir ?br>");
document.write ("-------------- ?br>");
for (i=0; i?4; i++)
/
document.write(list.ItemList(i) +"?br>");
}
document.write ("-------------- ?br>");

//-->
?/script>
?/body>
?/html>

0 komentar:

ekoprihastopo © 2008 Template by:
SkinCorner