-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.java
More file actions
57 lines (41 loc) · 1.12 KB
/
Search.java
File metadata and controls
57 lines (41 loc) · 1.12 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
package geeks.algo.search;
import java.util.Scanner;
public abstract class Search{
int[] inputArr;
int key;
String type;
String timeComplexity;
String spaceComplexity;
void getInput(){
Scanner in = new Scanner(System.in);
System.out.println("How many items: ");
int n= in.nextInt();
System.out.println("Enter Array");
this.inputArr = new int[n];
for(int i=0;i<n;i++){
this.inputArr[i]=in.nextInt();
}
System.out.println("Enter Key ");
this.key = in.nextInt();
in.close();
}
abstract boolean search();
abstract void setComplexities();
void performSearchTask(){
System.out.println("Inputs:");
getInput();
long startTime = System.nanoTime();
boolean found= search();
if(found){
System.out.println("Found Item.");
}else{
System.out.println("Didn't found the item.");
}
long endTime = System.nanoTime();
long diff = endTime - startTime;
System.out.println("Total time taken to search (in milliseconds): "+diff);
setComplexities();
System.out.println("Time Complexity : "+timeComplexity);
System.out.println("Space Complexity : "+spaceComplexity);
}
}