-
-
Save linkkingjay/6759874 to your computer and use it in GitHub Desktop.
随机排序,哈哈哈哈。
This file contains hidden or 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> | |
#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