SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Prak Sorting</title>
  5. </head>
  6. <body>
  7.     <h1>Insertion Sort</h1>
  8.     <span>Masukan Nilai : </span>
  9.     <br>
  10.     <input type="text" id="txtMasuk">
  11.     <br>
  12.     <input type="button" onclick="btnMasuk()" value="Input">
  13.     <input type="button" onclick="btnLihat()" value="Hasil Sorted">
  14.     <br>
  15.     <br>
  16.     <span>Hasil Input Data : </span>
  17.     <br>
  18.     <textarea id="txtAwal"></textarea>
  19.     <br>
  20.     <span>Hasil Sorted : </span>
  21.     <br>
  22.     <textarea id="txtAkhir"></textarea>
  23.     <script type="text/javascript">
  24.         var data = [];
  25.         var i,wall,j;
  26.  
  27.         function btnMasuk() {
  28.             data.push(document.getElementById("txtMasuk").value);
  29.             document.getElementById("txtAwal").value = data.join(" , ");
  30.             txtMasuk.value = "";
  31.             txtMasuk.focus();
  32.         }
  33.         function btnLihat() {
  34.             console.log("data awal"+data)
  35.             for (i = 1; i < data.length; i++)
  36.             {
  37.                 console.log("i:"+i);
  38.  
  39.                 wall = parseInt(data[i]);
  40.                 j = i - 1;
  41.                 console.log("wall:"+wall);
  42.                 console.log("j"+j)
  43.  
  44.                 while(j >= 0 && data[j] > wall)
  45.                 {
  46.                     console.log("While True");
  47.                     console.log("j: "+j);
  48.                     data[j + 1] = data[j];
  49.                     console.log("data[j+1]"+data[j+1]);
  50.                     console.log("data while"+data);
  51.                     j--;
  52.                 }
  53.                 data[j + 1] = wall;
  54.                 console.log("wall: "+wall);
  55.                 console.log("data[j+1] bwh: "+data[j+1]);
  56.                 console.log("data swap"+data);
  57.             }
  58.             document.getElementById("txtAkhir").value = data.join(" , ");
  59.         }
  60.  
  61.     </script>
  62.  
  63. </body>
  64. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top