<html>
<head><title>Struktur Data Antrian</title></head>
<script language = "JavaScript">
var queue = new Array();
function Masuk_Antrian(data) {
queue.push(data);
}
function Keluar_Antrian() {
var yang_keluar_antrian = queue.shift();
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>
<body>
<form>
<input type=text name=textSimpan size=7>
<input type=button value="Masuk Antrian"
onClick='Masuk_Antrian(textSimpan.value);
textSimpan.value="";
Dalam_Antrian(Visualisasi);'>
<select name="Visualisasi" size=7>
<option>isi antrian</option>
</select>
<input type=text name=textAmbil size=7>
<input type=button value="Keluar Antrian"
onClick="textAmbil.value = Keluar_Antrian();
Dalam_Antrian(Visualisasi);">
</form>
</body>
</html>
No comments:
Post a Comment