Silahkan Melihat-lihat... Semoga Bermanfaat...

13 Juli 2009

BAB V (Queue)

QUEUE STATIK

?html>
?head>
?title>Program Queue dengan Shift dan Unshift javascript?/title>
?script language = "javascript">

function DataQueue()
{
var queue = [];
queue.unshift(1);
queue.unshift(2);

var i = queue.pop();
document.write(i + "?br>");
queue.unshift(3);
queue.unshift(4);
var i = queue.pop();
document.write(i + "?br>");
}

?/script>
?/head>

?body>
?form name="FormStrukturData">
?input name="btnQueue" value="Queue" type="button"
onClick = "DataQueue();">
?/form>
?/body>
?/html>

QUEUE DINAMIK

?html>
?head>
?title>Struktur Data Queue?/title>
?script language = "javascript">

var queue = new Array();

function masuk_antrian(data)
{
queue.unshift(data);
}

function keluar_antrian()
{
var yang_keluar_antrian = queue.pop();
if (queue.length == 0)
return "Antrian Sudah Kosong";
else
return yang_keluar_antrian;
}

function dalam_antrian(list)
{
list.options.length = 0;
for (var i=0; i?queue.length; i++)
{
var data = new Option(queue[i]);
list.options[list.options.length] = data;
}
}

?/script>
?/head>
?body>
?form>
?input type=text name=textsimpan>
?input type=button value="Masuk Antrian"
onClick='masuk_antrian(textsimpan.value);
textsimpan.value="";
dalam_antrian(visualisasi);'>

?select name="visualisasi" size=12>
?option>Isi Antrian...
?/select>
?input type=text name=textambil size=20>
?input type=button value="Keluar Antrian"
onClick="textambil.value=keluar_antrian();
dalam_antrian(visualisasi);">
?/form>
?/body>
?/html>

Tidak ada komentar:

Posting Komentar