Muscardinus
버블정렬 본문
728x90
const numbers = [99, 44, 6, 2, 1, 5, 63, 87, 283, 4, 0];
function bubbleSort(array) {
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j+1]) {
let temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
return array;
}
bubbleSort(numbers);
// Space Complexity : O(1)
// Time Complexity(Worst): O(n^2)
728x90
Comments