-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
63 lines (47 loc) · 1.09 KB
/
main.c
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
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#ifdef __FIND_KTH_SMALLEST_NUMBER__
void build_array (int elem_num, int A[])
{
int elem ;
struct timeval tv ;
int n ;
gettimeofday (&tv, NULL) ;
srand (tv.tv_usec) ;
for (elem=rand()%50, n=0; n<elem_num; ++n) {
A[n] = elem ;
elem += rand () % 200 ;
}
}
int main (int argc, char *argv[])
{
FILE *stream ;
int len_a, len_b ;
int *A, *B ;
int k , n ;
len_a = atoi (argv[1]) ;
len_b = atoi (argv[2]) ;
// Read the first array
if (0 > len_a)
exit (1) ;
A = malloc (4*len_a) ;
printf ("[Array A]\nLength :\t%d\nElements :\t", len_a) ;
build_array (len_a, A) ;
// Read the second array
if (0 > len_b)
exit (1) ;
B = malloc (4*len_b) ;
printf ("\n[Array B]\nLength :\t%d\nElements :\t", len_b) ;
build_array (len_b, B) ;
printf ("\nEnter the index\n") ;
scanf ("%d", &k) ;
printf ("======>The result by simple way : %d\n",
simple_way (A, len_a, B, len_b, k)) ;
printf ("======>The result by best way : %d\n",
best_way (A, len_a, B, len_b, k)) ;
return 0 ;
}
#endif