Skip to content

Instantly share code, notes, and snippets.

@linkkingjay
Forked from wintercn/adhocSort.js
Last active December 24, 2015 06:49
Show Gist options
  • Save linkkingjay/6759874 to your computer and use it in GitHub Desktop.
Save linkkingjay/6759874 to your computer and use it in GitHub Desktop.
随机排序,哈哈哈哈。
#include<stdio.h>
#include<stdlib.h>
int is_sorted(int *s, int n) {
int i;
for (i = 0;i < n - 1;i++) {
if (s[i] > s[i + 1])
return 0;
}
return 1;
}
void random_sort(int *s, int n) {
int i, temp, random;
while (!is_sorted(s, n)) {
for (i = 0;i < n;i++) {
random = rand() % n;
temp = s[i];
s[i] = s[(i + random) % n];
s[(i + random) % n] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment