3 like 0 dislike
1.7k views
Write a Bubble Sort algorithm in JavaScript using object.
[Exercise] Essay (Open question) - asked in 2016-2 CSIEB0270 - Internet System Design and Practice by (18k points)
ID: 23133 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
0 0
<html>
<head>
<script>
var arr = [5, 6, 3, 10, 7, 2, 1, 4, 9];
function bubbleSort(arr) {
     var i, j;
     for (i = arr.length - 1; i >= 0; i--) {
         for (j = 0; j <= i; j++) {
             if (arr[j + 1] < arr[j]) {
                 var temp = arr[j];
                 arr[j] = arr[j + 1];
                 arr[j + 1] = temp;
             }
         }
     }
     return arr;
 }
 document.writeln(arr+"<br>");
 document.write(bubbleSort(arr));
 </script>
 </head>
 <body>

 </body>
 </html>

17 Answers

0 like 0 dislike
Hidden content!
* **** **** *** * * * * * * **** * * *
answered by (-85 points)
0 like 0 dislike
Hidden content!
* * * * ***** **** ***** * * ** ** * ** *
answered by (-32 points)
0 like 0 dislike
Hidden content!
* **** * * * * * ** * * **** * *
answered by (-211 points)
0 like 0 dislike
Hidden content!
* * ** **** **** ** ** * * *** **** **** * *
answered by (6 points)
0 like 0 dislike
Hidden content!
*** ** **** * **** * * * * *** *** * * ** *
answered by (42 points)
0 like 0 dislike
Hidden content!
** * ** * * ** * * ***** ** * * * **
answered by (72 points)
0 like 0 dislike
Hidden content!
<html>

    <script type="text/JavaScript">

        var number = [4,5,2,3,1];

             
** * * * **** * ***** * * * ** ** **** * **** **** *** *** ** ** ** bubbleSort(theArray) {
* ** * * * * * * ** * * * * * * ***** ** * * * * ** * ** * ** * **** ** ** * *** * i, j;
* * ** ** * ** * **** **** * * * * * **** * * ** * * ** ** ** *** ** *** ** ** ** * (i = theArray.length - 1; i >= 0; i--) {
* * ** *** * ** ****** * * * * * **** *** * * ** * *** * ** ** *** ***** * ****** * * * * * * * * ** * * ** * * (j = 0; j <= i; j++) {
*** * **** * * * * * *** ** * ** * **** ***** * * * ** * ** * ****** * *** *** ** ** * **** ** ** ** **** ***** *** ****** * ** (theArray[j + 1] < theArray[j]) {
** * * * ***** *** *** *** ** * * * * * * ** ** * * * *** ** ** * * ** ** * * **** * *** * * ** * * * *** *** * * ** ****** * * ****** * ****** * ** ** ** *** ** temp = theArray[j];
* * * * * *** *** * ** ** * * ** ********* * * * **** * * * * * * *** * **** ** * ** ** * * * * **** * * * **** * ** *** ** * ** ** * * = theArray[j + 1];
** *** * * * ** **** ***** ** * * ** * * * **** * * * * * ******** * * * * * **** *** * *** ** * ** ***** * ** ** * ** ** ** **** ** * + 1] = temp;
* ** ***** **** * * ** * ** * * * * *** * * ** *** * * ** ***** ** ** * *** * ** *** ** **** * * * ** *** *** * *
** * * *** *** *** * * ** * ** ** * * *** * *** ** * ** *** * * ****** * * *** ** ** ** *** * * ** *
* * ** *** * * **** ** * ** * * * * *** * ***** ***** * * * * * ** * ** **** *** * ** **
* ** * * ** * ****** * * * ** * *** ** * * * ** * * ** * * * ** * ** *** **** * theArray;
* ** * * ** ******* ** ** ** * ** * **** ** * * * ** ** ** * * *** * ** * *

             
* ***** * * * * * ** * ** ***** ** ** * * * *** *** * ** *** ** * *** * ** *** ** * printArray(theArray)
*** ** * ** * ******* * *** * * * *** *** ***** ***** *** ** * * * * ***
* *** * **** **** **** * ** * * * * * * *** ** * * * * **** **** ** * * ** * ** * * i=0;i<theArray.length;i++)
*** * * *** ** *** *** ** * * ** * * * ** * * * * **** * * * ** ** * * * ** * *** ** ***** **** ** ** * **** * * ** ****** * * * * ** * ****
* ** *** ***** * *** *** ** **** * *** ** * ** * * ***** * * * ***
* ** * ** * * * *** ** *** * *** ****** * *** * * ** ** * * * * ***
* *** * ** * * *** ** ***** ** *** *** * * * ** ** ** * ** * * * *** * *
* * *** ** * ** * ***** * * ** * *** ******* ** ******* ** **** *** *

    </script>

<body>



</body>



</html>
answered by (18 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.126.200
©2016-2025

Related questions

4 like 0 dislike
16 answers
[Exercise] Essay (Open question) - asked Mar 23, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23134 - Available when: Unlimited - Due to: Unlimited
| 1.6k views
3 like 0 dislike
17 answers
[Exercise] Multichoice - asked Mar 22, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23126 - Available when: Unlimited - Due to: 2017-03-23 09:30:00
| 1.4k views
2 like 0 dislike
0 answers
[Resource] asked Mar 23, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23132 - Available when: Unlimited - Due to: Unlimited
| 46 views
3 like 0 dislike
18 answers
[Exercise] True/False - asked Mar 22, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23130 - Available when: Unlimited - Due to: 2017-03-23 09:30:00
| 1.6k views
2 like 0 dislike
26 answers
[Exercise] Multichoice - asked Mar 22, 2017 in 2016-2 CSIEB0270 - Internet System Design and Practice by Shun-Po (18k points)
ID: 23129 - Available when: Unlimited - Due to: Unlimited
| 2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users