Can someone explain to me how this sorting algo is working, and what is the name of this algorithm?

Talk about things C/C++, some related to AutoHotkey
Soham1087
Posts: 2
Joined: 15 Jun 2022, 04:26

Can someone explain to me how this sorting algo is working, and what is the name of this algorithm?

15 Jun 2022, 04:29

I have created a sorting function. Can I know the name of this algorithm? Is this bubble sort?

I am new in C.

Code: Select all

#include <stdio.h>

void sort(int *, int);

int main(void) {
    int arrayNum[] = {1, 12, 8, 4, 90, 11, 76};
    int len = sizeof(arrayNum) / sizeof(arrayNum[0]);
    sort(arrayNum, len);
    for (int i = 0; i < len; i++) {
        printf("%d, ", arrayNum[i]);
    }
    
    return 0;
}

void sort(int *array, int length) {
    int temp;
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (array[i] < array[j]) {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
    }
}

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 54 guests