#define TEST_1
#ifdef TEST_1
#include "array_search.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int array1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55};
int array2[] = {1,10,15,30,400,401,402,600,620,640,650,700,701,702,705,2000,2005,3000,3200,3400,3500,3600,6000,6200,6500,6700,6800,6801,6803,8000,9001,9010,9100,9300,9500,9601,9602,9802,9900};
int array3[] = {343, 1540, 1562, 2135, 2275, 2559, 3780, 4440, 4946, 6110, 6200, 7040, 7290, 7541, 7881, 9269};
printf(
"Arrays available:\n"
"1)array1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55}\n"
"2)array2[] = {1,10,15,30,400,401,402,600,620,640,650,700,701,702,705,2000,2005,3000,3200,3400,3500,3600,6000,6200,6500,6700,6800,6801,6803,8000,9001,9010,9100,9300,9500,9601,9602,9802,9900}\n"
"3)array3[] = {343, 1540, 1562, 2135, 2275, 2559, 3780, 4440, 4946, 6110, 6200, 7040, 7290, 7541, 7881, 9269};\n"
);
int number;
clock_t start, end;
double cpu_time_used;
size_t array1_len = sizeof(array1) / sizeof(array1[0]);
size_t array2_len = sizeof(array2) / sizeof(array2[0]);
size_t array3_len = sizeof(array3) / sizeof(array3[0]);
size_t idx;
while(1) {
printf("Enter array number:");
scanf("%d", &number);
int *p;
size_t len;
switch (number)
{
case 1:
p = array1;
len = array1_len;
break;
case 2:
p = array2;
len = array2_len;
break;
case 3:
p = array3;
len = array3_len;
break;
default:
p = NULL;
len = 0;
exit(0);
break;
}
printf("Enter a key to find in array %d: ", number);
scanf("%d", &number);
printf("You entered: %d\n", number);
start = clock();
bool b = ibs_valIsInArray(&number, p, sizeof(int), 0, len, &idx, subtract_int, compare_int);
end = clock();
if(b) {
printf("Found at idx: ");
} else {
printf("Not found. idx is at :");
}
printf("%zu\n", idx);
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("Time taken for IBS in array: %f seconds\n", cpu_time_used);
start = clock();
b = sq_valIsInArray(&number, p, sizeof(int), 0, len, &idx, compare_int);
end = clock();
if(b) {
printf("Found at idx: ");
} else {
printf("Not found. idx is at :");
}
printf("%zu\n", idx);
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("Time taken for SQ in array: %f seconds\n", cpu_time_used);
}
return 0;
}
#endif