-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbadSort.c
More file actions
28 lines (26 loc) · 730 Bytes
/
badSort.c
File metadata and controls
28 lines (26 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "esotericFunMiscellaneous.h"
// O(n**3)
// Bad implementation of selection sort
void badSort(long int *array, int length){
long int aux, *smaller, *i, *j, *k;
bool check;
for(i = array; i < array + length; i++){
smaller = i;
for(j = i; j < array + length; j++){ // Find the smaller element
check = true;
for(k = j + 1; k < array + length; k++){
if(*j > *k){ // Check if *j is the smaller
check = false;
break;
}
}
if(check){
smaller = j;
break;
}
}
aux = *i;
*i = *smaller;
*smaller = aux;
}
}