亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

js writes a bubble sort
抖音用戶822461946
抖音用戶822461946 2024-01-19 16:08:09
0
0
1645

function bubbleSort(arr) {

let n = arr.length;


for (let i = 0; i < n-1 ; i ) {

for (let j = 0; j < n-i-1; j ) {

if (arr[j] > arr[j 1]) {

//Exchange arr[j 1] and arr[j]

let temp = arr[j];

arr[j] = arr[j 1];

arr[j 1] = temp;

}

}

}


return arr ;

}


// Test

let arr = [64, 34, 25, 12, 22, 11, 90] ;

console.log("The array before sorting is: ");

console.log(arr.join(" "));


arr = bubbleSort(arr);

console.log("The sorted array is: ");

console.log(arr.join(" ")) ;


抖音用戶822461946
抖音用戶822461946

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template