-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
57 lines (48 loc) · 1023 Bytes
/
common.cpp
File metadata and controls
57 lines (48 loc) · 1023 Bytes
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
#include "common.h"
void printArray(int*a,int low,int high) {
if(!a) return;
if(low<0) return;
for(int i=low; i<=high; ++i)
printf("%d ",a[i]);
printf("\n");
}
void printArray(int*a,int n) {
printArray(a,0,n-1);
}
//ÊͷŶþάÊý×é
void free_Array2D(void **arr) {
if(arr != NULL)
free(arr);
}
//Test utils
void assertSorted(int *x,int n) {
for(int i=1; i<n; ++i)
if(x[i-1]>x[i])
assert(false);
}
void createRandomData(int* keys,int n) {
time_t seed;
time(&seed);
srand(seed);
for(int i=0; i<n; ++i)
keys[i]=rand()%n;
}
void createRandomUniqPostiveData(int* keys,int n) {
time_t seed;
time(&seed);
srand(seed);
for(int i=0; i<n; ++i)
keys[i]=i;
int a=0,b=0;
for(int i=0; i<n; ++i) {
a=rand()%n;
b=rand()%n;
swap(keys,a,b);
}
}
//template<class T>
//void display(T a[],int n) {
// for(int i=0; i<n; i++)
// std::cout<<a[i]<<" ";
// std::cout<<std::endl;
//}