3 like 0 dislike
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
| 732 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 (31.4k points)
0 like 0 dislike
Hidden content!
* ** * **** * *** * * ** ** ** * * ***
answered by (12 points)
0 like 0 dislike
Hidden content!
** * * * ***** * * *** * * * ********* **
answered by (87 points)
0 like 0 dislike
Hidden content!
<!-- I'm sorting 2 different arrays. 1-numbers. 2-objects -->



<!DOCTYPE html>

<html>

<head>

    <title>Buble Sort</title>

    <script>



        /* I'm sorting 2 different arrays. 1-numbers. 2-objects */
** ****** * * * * ** ** *** * * ** *** * * ** * * numbers=[45, 85, 96, 11, 1, 5, 2, 34];
*** * * ***** *** ***** ***** * **** *** ** ** * ** BubleNumbers(arr)

        {
*** ***** * ** * ** ** * ** * * * ** ** * ** * ** * **** flag;
* ***** * ** **** ** *** ** ** *** * ** * ** ** * ** * * ** * *
***** *** * * ** * * ***** * *** * * * * ** **** ******** * * * * **** * ****** * ***
* * * ** *** * ** * ** * * * *** * ** *** *** ***** * * * *** * * * ** * * *** (var i=0; i < arr.length-1; i++)
** *** * * ****** * ** * ** * * * ******* ** ****** * * * ** ** *

    
*** * * * ***** * * ** **** * * **** ** * * * * ** * * * ****** * ***** *** * * ** ** ***** * ** * * * * *** * * * * * **
* * **** ***** **** * **** * *** * * * **** * * *** * ** * ******* * ** * ** ** * ** * * * ** * * ** **
** ** * *** * ** * ** * * * *** *** ** ***** * * ** * *** * ** * ** ****** * **** * ** * ** * * *** *** * * * ** * * **** * temp=arr[i];
* ** * * * * * ** * * ** * * ** *** ** ** ** ** *** *** * * * ** ** ** * *** * * *** ** * * ***** * * * *** * ****** * * *
* ** ** * * *** **** * * * *** ** *** *** * *** * * *** * ** ** * ***** * *** ** * * * * *** * * *** ** ** * * * * ** *** ** ** * *
** * **** * *** **** *** * * * * ** * ** *** * * * ** ** * ******** *** * ** * *** **** ** * * ** *** *** * * *** * ** **** * * * * * * * ** ** *** * * * * ** * ** *** * ** * * * * ****** * ** * * * * ** ***** * * *** **
* ** * ** * * * ** ** * * * * * ** *** * *** ** ***** ** **** **** ** ****** * ***** * ***** ** * ***** * ** **
* ** ***** ** * * ****** * * **** * * ** * * * ** **** * * ** *** **** * * * * * * * *
*** * ** * * **** ** ** ******* ** * * * *** **** * * **** * ** ** while(flag)

        }    
* ** * * * * ****** ** ** ** ** * * * * * *** * *
* ** * ** * *** * * *** * * ** **** ** (var i = 0; i < numbers.length; i++)
* **** * ** * ** * *** * * ***** *** * ***** * ** ** * ** ** ***** *** **** **** *** * **** *


* ** * * * * ********* ** * * ** *** * * Friuts =[
* * ** * * ** * ** *** * * ** * ** **** * * * ** * * ** * * * ** ** color:"black", weight:300, amount:100},
* * * * * * * ***** ** ** * *** * * ** * * ** * * * * * *** ** * * * * ** *** *** ** * color:"yellow", weight:100, amount:30},
* *** ** * ** * * * * * * **** * * * ** * ****** ** * ****** ** ***** * ** color:"orange", weight:150, amount:55},
*** * ** ******** **** * * ** ** * ** *** * * * *** * ** * * ** *** * * color:"cream", weight:120, amount:40},
**** ** * * *** ** * * * ***** ***** * * ** *** ** **** * * * *** ** color:"green", weight:700, amount:150}];
*** * *** *** * ***** * ** * *** * * ** * *** ** BubleObject(arr, pat)

        {
* * * * **** * ** * ** * * **** * *** ** *** * ** * **** *** * * flag;
*** * *** * ** * **** *********** *** **** * * ** **** * * ** **
* * * * * ****** * * *** * * * * ** * * * * * * * * * * * * ** *** ** **** * * * ** * **
* * * * * * ** *** * * * ** * *** ** * ** * * * * * * ** * ** ** ***** * ** ** ** i=0; i<arr.length-1 ;i++)
* ** * * * ** * * * * * * ** **** **** * ****** *** **** ** *** ******* *** ** *
** ** * * ** * * * * * ** * * * * * * * **** * ** ** ** *** * *** ****** * ** ** **** * ** *** * *** ** * *
** ** **** ** **** * *** *** **** * ** ** *** *** ** ** **** ** *** * * * ** **** ****** *** ** **** *** ******* ** ** ***
*** ** * * * *** * ****** *** *** ** *** *** **** * ****** ** * * **** ** ** ** * ***** * * * * * ** ** ** * ** *** ***** * * * ** * temp=arr[i];
**** *** * * *** * * *** **** * * * *** * *** * * ** ** * * ******** ** * * * *** * * * * *** * * * *** * ** ** *
**** * * * ***** * *** ** * * ** * *** *** * ** *** ** ** * ** ** *** * ** *** *** ** * ** * ******** ** ******** ** * ** ***
* ****** * * *** * * * ***** * * * * **** ** * ** *** * * * ******* *** ** * * * *** * ***** ** * * * ** ** ***** *** * * *
** * ** * * *** * * ** * ** * * * * * **** * * * * * * * ** * ***** * **** *** * ***** * * ** *
* ** * * ** **** * **** ** * * * * ** ** ** * * ** * * ** **** ** * * * ** * *
* ** * ** * * ** * ** ** *** * ** * * * * ** * *** * **** * * * *****

        

        }
* ** *** * *** *** ** * * ** *** **** * * * * * ** * 'name');
* ****** * ******** ** **** ** *** * ** **** ** ** i=0; i<Friuts.length; i++)
** **** ** ** * ******** ** **** * * ** **** ** * * * ******** ***** * ** *

    </script>

</head>

<body>

    <h3>Buble sort</h3>

</body>

</html>
answered by (-335 points)
edited by
0 like 0 dislike
Hidden content!
******* * ***** ** ** *** *** *
answered by (-61 points)
0 like 0 dislike
Hidden content!
* * ** ** * * * * * * ** * *
answered by (-61 points)
0 like 0 dislike
Hidden content!
* * * * * *** * *** * **** * ** ** * ** *
answered by (-10 points)
0 like 0 dislike
Hidden content!
* * * ** * ** * * * *** * ** **** * * * *
answered by (-144 points)
0 like 0 dislike
Hidden content!
** * * ***** ** *** * *** *** * ** ** ****
answered by (-103 points)
0 like 0 dislike
Hidden content!
Array.prototype.bubbleSort_algo = function()



{



var is_ sorted = false;


*** * ** * * * *** ** * (!is_sorted)



    {


*** * * * *** * ** ** * * ***** * * * **** * = true;


*** * * ** *** * **** ** * * *** **** ** * (var n = 0; n < this.length - 1; n++)


**** * ** * **** **** *** ***** ** * ** * * **


* ***** *** * ** ***** ** ** * ** * *** ****** ** * *** * * * ** * ** **** (this[n] > this[n+1]) {


*** ****** ** ** * * ** * * **** *** ** * ** * * * * ** ***** * **** *** ** *** *** * * * *** *** **** x = this[n+1;


* *** * ** * *** ** * * ***** * ****** ** * * * * * * ** * ** * ** ** * ** * **** * ** *** * ** * ** ** * = this[n];


* * * *** ** * ****** * * **** * * * ** * * * ** * * * ** ** ** **** ** ** * ******** *** * * * ** **** * ** = x;


* ** ******** ***** ** ** ** ** * * * * * * ** *** ** * *** * ***** **** ** ** * * **** * *** ***** * *** ** ** ** = false;


**** * * * * **** * * *** * * * ** * * * * * * *** * *** * * *** * *** * ****** ** * **** ** * **


** ** * **** * * **** * * ** * ** * **** ** * * * * * *** **



   }


* ** * ** *** ** ** * * this;



};



console.log( [n].bubbleSort_algo() );
answered by (-233 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.134.210
©2016-2022

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
| 702 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
| 557 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
| 669 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
| 775 views
13,829 questions
209,706 answers
189,808 comments
5,435 users