Last active
March 8, 2016 12:20
-
-
Save zYeoman/2ca0762f038e0a8d74c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
char weight[10]; | |
int compare(const char *a, const char *b){ | |
return weight[*a]-weight[*b]; | |
} | |
void ShuffleArray_Sort(char* arr, int len){ | |
for (int j = 0; j < 10; ++j){ | |
weight[j] = rand(); | |
} | |
qsort( (void *)arr, (size_t)len, sizeof(char), compare ); | |
} | |
int compare_wrong(const char *a, const char *b){ | |
return rand()%2*2-1; | |
} | |
void ShuffleArray_Sort_Wrong(char* arr, int len){ | |
qsort( (void *)arr, (size_t)len, sizeof(char), compare_wrong); | |
} | |
int main(){ | |
int result[10][10] = {0}; | |
const size_t len = 10; | |
for (int i = 0; i < 100000; ++i){ | |
char arr[10] = {0,1,2,3,4,5,6,7,8,9}; | |
ShuffleArray_Sort_Wrong(arr, len); | |
for (int j = 0; j < 10; ++j){ | |
result[arr[j]][j]++; | |
} | |
} | |
for (int i = 0; i < 10; ++i){ | |
for (int j = 0; j < 10; ++j){ | |
printf("%10d", result[i][j]); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment