-
Notifications
You must be signed in to change notification settings - Fork 0
/
mWaySearch.java
60 lines (58 loc) · 1.83 KB
/
mWaySearch.java
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
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
/**
* Created by hepstev on 09.02.16.
*/
public class mWaySearch {
public static void Print(Object ob){
System.out.println(ob);
}
public static void main(String[] args){
int[][] keys = new int[4]/*anzahl der db*/[3]/*anzahl der ds*/;
keys[0][0] = 7;
keys[0][1] = 9;
keys[0][2] = 20;
keys[1][0] = 25;
keys[1][1] = 27;
keys[1][2] = 32;
keys[2][0] = 44;
keys[2][1] = 57;
keys[2][2] = 69;
keys[3][0] = 84;
keys[3][1] = 84;
keys[3][2] = 84;
ArrayList<Integer> searchKeys = new ArrayList<>();
for(int p=0; p<keys.length;p++){
for(int q=0;q<keys.length-1;q++){
searchKeys.add(keys[p][q]);
}
}
Set<Integer> toSearch = new HashSet<>();
toSearch.addAll(searchKeys);
searchKeys.clear();
searchKeys.addAll(toSearch); //duplizierungen entfernt
ArrayList<Integer> compares = new ArrayList<>();
for(int g = 0; g < searchKeys.size();g++){
int search = searchKeys.get(g);
int c = 1;
for(int i = 0; i<keys.length;i++,c++){
if(search <= keys[i][keys.length-2]){
for(int j = 0; j<keys.length-1;j++,c++){
if(search == keys[i][j]){
c++;
compares.add(c);
i = keys.length;
j = keys.length;
}
}
}
}}
int sum = 0;
for(int h=0; h<compares.size();h++){
sum+=compares.get(h);
}
double averageCompares = (double)sum/searchKeys.size();
Print(averageCompares);
}
}