猴子排序
让一群猴子在打印机前昼夜不停地敲打键盘,最终有可能能输入一部莎士比亚作品集——尽管概论微乎其微。
同理,把一堆扑克牌扔到天上,等它们落下来的时候有概率会刚刚好从小到大排成一列。
现在有一个无序的数组,我们让一只猴子来帮我们进行排序:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>
#define RAND(N) rand() % N
long long monkeySort(int *array, int size);
int main()
{
int n; //size
int repeat = 20; // 为了科学严谨的精神,多次实验取平均值
srand(time(NULL));
for (int n = 0; n <=