-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexchangeBogoSort.c
More file actions
24 lines (23 loc) · 815 Bytes
/
exchangeBogoSort.c
File metadata and controls
24 lines (23 loc) · 815 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
#include "esotericFunMiscellaneous.h"
void exchangeBogoSort(long int *array, int length){
int random1, random2;
long int aux;
while(!isSortedRandomly(array, length)){
random1 = rand() % length;
random2 = rand() % length;
if(random1 < random2){ // Check the positions
if(*(array + random1) > *(array + random2)){ // Check if it's sorted
aux = *(array + random1);
*(array + random1) = *(array + random2);
*(array + random2) = aux;
}
}
else{
if(*(array + random1) < *(array + random2)){ // Check if it's sorted
aux = *(array + random1);
*(array + random1) = *(array + random2);
*(array + random2) = aux;
}
}
}
}