C srand()和生成用于算法测试的数组

C srand()和生成用于算法测试的数组,c,arrays,sorting,testing,C,Arrays,Sorting,Testing,我创建了一个选择排序算法。我想用各种输入测试我的程序 在不实际输入每个数组元素的情况下,如何使用操纵数组的算法实现排序、反向排序和随机数组(固定长度[即100000])以进行测试 对于随机数组,我通常使用如下函数: int* big_random_block_int( int size ) { int *data = (int*)malloc( size * sizeof(int) ); int i; for (i=0; i<size; i++) data[i] = rand();

我创建了一个选择排序算法。我想用各种输入测试我的程序


在不实际输入每个数组元素的情况下,如何使用操纵数组的算法实现排序、反向排序和随机数组(固定长度[即100000])以进行测试

对于随机数组,我通常使用如下函数:

int* big_random_block_int( int size ) {
int *data = (int*)malloc( size * sizeof(int) );
int i;
for (i=0; i<size; i++)
    data[i] = rand();

return data;
}
int*big\u random\u block\u int(整数大小){
int*data=(int*)malloc(size*sizeof(int));
int i;

对于(i=0;i,您需要编写一些函数来生成排序函数的输入。类似如下:

void mySort(int* a, int n) {
    // your sorting algorithm goes here.
}

// Generates some increasing sequence of numbers into a[0] .. a[n-1].
void generateSorted(int* a, int n) {
    for (int i = 0; i < n; ++i) {
        a[i] = 42 + i * i;  // for example. 
    }   
}

// Generates some decreasing sequence of numbers into a[0] .. a[n-1].
void generateSorted(int* a, int n) {
    for (int i = 0; i < n; ++i) {
        a[i] = 37 - (5 * i);
    }   
}

// Generates a random sequence of numbers into a[0] .. a[n-1],
// each number in [0, n).
void generateRandom(int* a, int n) {
    for (int i = 0; i < n; ++i) {
        a[i] = rand() % n;
    }   
}

void testSortingFunctionOnDifferentInputs() {
    int a[100];
    generateSorted(a, 100);
    mySort(a, 100);
    generateReverseSorted(a, 100);
    mySort(a, 100);
    generateRandom(a, 100);
    mySort(a, 100);
} 
void mySort(int*a,int n){
//你的排序算法在这里。
}
//将一些递增的数字序列生成为[0]…a[n-1]。
无效生成已启动(int*a,int n){
对于(int i=0;i