/* test5.c 配列撹拌ルーチンテスト */
#include <stdio.h>
#include <stdlib.h>
#include "random.h"
main()
{
int i, j, len, n, *data_i, *ip;
double *data_d, *dp;
unsigned char **data_c, **sp, *spp;
n = 25;
len = 2;
data_i = (int *)malloc(n * sizeof(int));
data_d = (double *)malloc(n * sizeof(double));
data_c = (unsigned char **)malloc(n * sizeof(unsigned char *));
for(i = 0, sp = data_c; i < n; i++)
*sp++ = (unsigned char *)malloc((len + 1) * sizeof(unsigned char));
for(i = 0, ip = data_i, dp = data_d, sp = data_c; i < n; i++)
{
*ip++ = *dp++ = i + 1;
for(j = 0, spp = *sp++; j < len; j++) *spp++ = 'a' + i;
*spp = '\0';
}
printf("*** before shuffle ***\n");
printf("* data_i\n");
for(i = 0, ip = data_i; i < n; i++) printf("%3d", *ip++);
printf("\n* data_d\n");
for(i = 0, dp = data_d; i < n; i++) printf("%3.0f", *dp++);
printf("\n* data_c\n");
for(i = 0, sp = data_c; i < n; i++) printf("%3s", *sp++);
putchar('\n');
shuffle_i(data_i, n, 1L);
shuffle_d(data_d, n, 2L);
shuffle_c(data_c, n, 3L);
printf("\n*** after shuffle ***\n");
printf("* data_i\n");
for(i = 0, ip = data_i; i < n; i++) printf("%3d", *ip++);
printf("\n* data_d\n");
for(i = 0, dp = data_d; i < n; i++) printf("%3.0f", *dp++);
printf("\n* data_c\n");
for(i = 0, sp = data_c; i < n; i++) printf("%3s", *sp++);
putchar('\n');
return 1;
}
|