Satyam S
Satyam S

Reputation: 31

What is the name of my sorting algorithm?

I have written a sorting algorithm. What is the name of this algorithm?

void sort(int *arr, size_t len) {
    int flag = 1, temp;
    while (flag != 0) {    
        flag = 0;
        for (int i = 0, j = 1; i < len - 1; i++, j++) {
            if (arr[i] > arr[j]) {
                flag = 1;
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
}

Upvotes: 0

Views: 88

Answers (1)

John Kugelman
John Kugelman

Reputation: 361615

This is bubble sort: repeatedly loop over an array swapping adjacent elements and stop when nothing is swapped.

Upvotes: 4

Related Questions