Skip to content

Update send_your_name.txt#35

Open
Viktoriia2309 wants to merge 1 commit into
tel-ran-de:mainfrom
Viktoriia2309:patch-2
Open

Update send_your_name.txt#35
Viktoriia2309 wants to merge 1 commit into
tel-ran-de:mainfrom
Viktoriia2309:patch-2

Conversation

@Viktoriia2309

Copy link
Copy Markdown

Домашнее задание / Квадратичная сложность , потом что "2 n"

function reverseBubbleSort(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]) {
// меняем arr[j] и arr[j+1] местами
let temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}

let arr = [64, 34, 25, 12, 22, 11, 90];
console.log("Отсортированный массив:", reverseBubbleSort(arr));

Домашнее задание / Квадратичная сложность , потом что "2 n"


function reverseBubbleSort(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]) {
                // меняем arr[j] и arr[j+1] местами
                let temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
    return arr;
}

let arr = [64, 34, 25, 12, 22, 11, 90];
console.log("Отсортированный массив:", reverseBubbleSort(arr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant