Friday, March 25, 2011

Suratku Untukmu ( Stack )

<html> <head> <title>Penggunaan Struktur Data Stack (Tumpukan)</title> <script language="javascript"> <!-- var stack = new Array(); function input_ke_stack(data) { stack.push(data); } function ambil_dari_stack() { var yang_ambil_dari_stack = stack.pop(); if (stack.length == 0) return (yang_ambil_dari_stack + " -> stack sudah kosong"); else return yang_ambil_dari_stack; } function dalam_antrian(list) { list.options.length = 0; for (var i = 0; i < stack.length; i++) { var data = new Option(stack[i]); list.options[list.options.length] = data; } } //--> </script> </head> <body> <font color=#992811>Visualisasi stack (Tumpukan)</font> <form> <input type=text name=textSimpan> <input type=button value="Masuk Tumpukan" onClick = 'input_ke_stack(textSimpan.value); textSimpan.value = ""; dalam_antrian(visualisasi);'> <select name="visualisasi" size=12> <option>Isi antrian.... </select> <br> <input type=text name=textAmbil size=20> <input type=button value="Keluar Dari Tumpukan" onClick='textAmbil.value = ambil_dari_stack(); dalam_antrian(visualisasi);'> </form> </body> </html>

0 komentar:

Post a Comment

Tinggalkan Komentar Disini