Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <meta CHARSET="UTF8">
- <head>
- </head>
- <body>
- <form style="
- PADDING-RIGHT: 4px;
- PADDING-LEFT: 4px; PADDING-BOTTOM: 1px;
- name="frmbubblesort">
- <p style="TEXT-ALIGN: center">
- <input onclick="main()" type="button" value="Sortuj losowe liczby" name="B1">
- </p>
- <p id="t_out" style="TEXT-ALIGN: center">...</p>
- </form>
- <script>
- N = 20; // Zbiór
- function main()
- {
- d = new Array(N);
- var i,j,x,t;
- //Tablica z liczbami losowymi
- for(i = 0; i < N; i++) d[i] = Math.floor(Math.random() * 100);
- t = "Przed sortowaniem:<BR><BR>";
- for(i = 0; i < N; i++) t += d[i] + " ";
- t += "<BR><BR>";
- // Sortujemy
- for(j = 0; j < N - 1; j++)
- for(i = 0; i < N - 1; i++)
- if(d[i] > d[i + 1])
- {
- x = d[i]; d[i] = d[i + 1]; d[i + 1] = x;
- };
- // Wynik sortowania
- t += "Po sortowaniu:<BR><BR>";
- for(i = 0; i < N; i++) t += d[i] + " ";
- document.getElementById("t_out").innerHTML = t;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement