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

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Can someone explain to me how this sorting algo is working, and what is the name of this algorithm?

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

Post by Soham1087 » 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;
            }
        }
    }
}

Top