forked from destiny1020/algorithm_playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitonic.java
More file actions
56 lines (47 loc) · 1.08 KB
/
Bitonic.java
File metadata and controls
56 lines (47 loc) · 1.08 KB
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
package chap1;
import gadget.CustomRandom;
//import gadget.Sorts;
public class Bitonic
{
private int N;
private int mid_index;
private int[] bi_array;
private boolean hasPeak;
public Bitonic(int N, boolean hasPeak)
{
this.N = N;
this.hasPeak = hasPeak;
}
public int[] createBiArray()
{
// Init the array
this.bi_array = new int[N];
// Init the mid index
this.mid_index = CustomRandom.uniform(0 + N / 5, (4 * N / 5) + 1);
for(int i = 1; i < this.mid_index; i++)
{
if(hasPeak)
{
this.bi_array[i] = this.bi_array[i - 1] + 1 + CustomRandom.uniform(10);
}
else
{
this.bi_array[i] = this.bi_array[i - 1] - 1 - CustomRandom.uniform(10);
}
}
// Set the mid_index
this.bi_array[this.mid_index] = this.bi_array[this.mid_index - 1] + CustomRandom.uniform(11) - 5;
for(int i = this.mid_index + 1; i < N; i++)
{
if(hasPeak)
{
this.bi_array[i] = this.bi_array[i - 1] - 1 - CustomRandom.uniform(10);
}
else
{
this.bi_array[i] = this.bi_array[i - 1] + 1 + CustomRandom.uniform(10);
}
}
return bi_array;
}
}