Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 = 1;
        for (int i = 0, j = 1; i < len - 1; i++, j++) {
            if (arr[i] > arr[j]) {
                flag = 2;
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        if (flag != 2) break;
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading