-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathQuickSortData.java
More file actions
42 lines (30 loc) · 999 Bytes
/
QuickSortData.java
File metadata and controls
42 lines (30 loc) · 999 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
public class QuickSortData {
private int[] numbers;
public int l, r;
public boolean[] fixedPivots;
public int curPivot;
public int curElement;
public QuickSortData(int N, int randomBound){
numbers = new int[N];
fixedPivots = new boolean[N];
for( int i = 0 ; i < N ; i ++) {
numbers[i] = (int)(Math.random()*randomBound) + 1;
fixedPivots[i] = false;
}
}
public int N(){
return numbers.length;
}
public int get(int index){
if( index < 0 || index >= numbers.length)
throw new IllegalArgumentException("Invalid index to access Sort Data.");
return numbers[index];
}
public void swap(int i, int j) {
if( i < 0 || i >= numbers.length || j < 0 || j >= numbers.length)
throw new IllegalArgumentException("Invalid index to access Sort Data.");
int t = numbers[i];
numbers[i] = numbers[j];
numbers[j] = t;
}
}