Pages

Questão EPO - Bubble sort

Sabemos que no Bubble Sort , o algoritmo faz as trocas dos números consultando em uma única direção do vetor. No código abaixo, o que deve ser atribuído ao declararmos a variável Swapped, quando está dentro do while e dentro do for?   

void bubbleSort(int arr[], int n) {
    bool swapped = _____;
    int j = 0;
    int tmp;
    while (swapped) {
        swapped = _____;
        j++;
        for (int i = 0; i < n - j; i++) {
            if (arr[i] > arr[i + 1]) {
                tmp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = tmp;
                swapped = ______;
            }
        }
    }
}

a) True – False – True;
b) False – True – True;
c) True – False – False;
d) False – True – False;
e) NDA;

Fonte:
http://www.algolist.net/Algorithms/Sorting/Bubble_sort

Um comentário:

Anônimo disse...

Letra A

A Função Swapped começa com True.... depois é só seguir a lógica.

Att.
Carol

Postar um comentário

 
Copyright (c) 2010. Blogger templates by Bloggermint