Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <meta CHARSET="UTF8">
  3. <head>
  4. </head>
  5. <body>
  6. <form style="
  7. PADDING-RIGHT: 4px;
  8. PADDING-LEFT: 4px; PADDING-BOTTOM: 1px;
  9. name="frmbubblesort">
  10.  
  11.  
  12. <p style="TEXT-ALIGN: center">
  13. <input onclick="main()" type="button" value="Sortuj losowe liczby" name="B1">
  14. </p>
  15. <p id="t_out" style="TEXT-ALIGN: center">...</p>
  16. </form>
  17.  
  18. <script>
  19.  
  20.  
  21. N = 20; // Zbiór
  22.  
  23. function main()
  24. {
  25. d = new Array(N);
  26. var i,j,x,t;
  27.  
  28. //Tablica z liczbami losowymi
  29.  
  30. for(i = 0; i < N; i++) d[i] = Math.floor(Math.random() * 100);
  31. t = "Przed sortowaniem:<BR><BR>";
  32. for(i = 0; i < N; i++) t += d[i] + " ";
  33. t += "<BR><BR>";
  34.  
  35. // Sortujemy
  36.  
  37. for(j = 0; j < N - 1; j++)
  38. for(i = 0; i < N - 1; i++)
  39. if(d[i] > d[i + 1])
  40. {
  41. x = d[i]; d[i] = d[i + 1]; d[i + 1] = x;
  42. };
  43.  
  44. // Wynik sortowania
  45.  
  46. t += "Po sortowaniu:<BR><BR>";
  47. for(i = 0; i < N; i++) t += d[i] + " ";
  48. document.getElementById("t_out").innerHTML = t;
  49. }
  50.  
  51. </script>
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement