-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearching.java
More file actions
65 lines (53 loc) · 1.35 KB
/
Searching.java
File metadata and controls
65 lines (53 loc) · 1.35 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
57
58
59
60
61
62
63
64
65
package geeks.algo.search;
import java.util.Scanner;
public class Searching {
static enum SearchingType {
LINEAR_SEARCH, BINARY_SEARCH, JUMP_SEARCH, INTERPOLATION_SEARCH, EXPONENTIAL_SEARCH
}
Search search;
SearchingType type;
public Searching() {
super();
this.type=SearchingType.BINARY_SEARCH;
}
public Search getSearch() {
return search;
}
public void setSearch(Search search) {
this.search = search;
}
void performSearch() {
Scanner in = new Scanner(System.in);
System.out.println("Searching Types: ");
for(int i=0;i<SearchingType.values().length; i++){
System.out.println((i+1)+". "+SearchingType.values()[i]);
}
System.out.println("Enter our choice");
int temp = in.nextInt();
type = SearchingType.values()[temp-1];
switch(type){
case LINEAR_SEARCH:
this.setSearch(new LinearSearch());
break;
case BINARY_SEARCH:
this.setSearch(new BinarySearch());
break;
case JUMP_SEARCH:
this.setSearch(new JumpSearch());
break;
case INTERPOLATION_SEARCH:
this.setSearch(new InterpolationSearch());
break;
case EXPONENTIAL_SEARCH:
this.setSearch(new ExponentialSearch());
break;
default:
this.setSearch(new BinarySearch());
}
this.search.performSearchTask();
}
public static void main(String[] args) {
Searching searching = new Searching();
searching.performSearch();
}
}