#include
int main(void)
你那一个代码感觉上下都有问题~~ 啊涂涂 发表于 2018-10-16 20:57
#include
int main(void)
快多了~~#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int in_order(int array[], int length);
void shuffle(int array[], int length);
void bogo_sort(int array[], int length);
int in_order(int array[], int length)
{
int i = 0;
while (array <= array && i++ < length - 1)
;
if (i == length - 1)
{
return 1;
}
else
{
return 0;
}
}
void shuffle(int array[], int length)
{
int index, temp;
index = rand() % (length);
if (index)
{
temp = array;
array = array;
array = temp;
}
}
void bogo_sort(int array[], int length)
{
srand(0);
while (!in_order(array, length))
{
shuffle(array, length);
}
}
void print(int arr[], int n)
{
for(int i = 0; i < n; i++)
printf("%d ", arr);
printf("\n");
}
int main(void)
{
int array[] = {73, 108, 111, 118, 101, 70, 105, 104, 67};
int i, length;
time_t begin, end;
begin = time(NULL);
length = sizeof(array) / sizeof(array);
bogo_sort(array, length);
printf("排序后的结果是:");
print(array, length);
end = time(NULL);
printf("总共耗时:%0.4lf秒\n", (double)(end - begin)/CLOCKS_PER_SEC);
return 0;
}
页:
1
[2]