-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort.java
More file actions
40 lines (30 loc) · 845 Bytes
/
Sort.java
File metadata and controls
40 lines (30 loc) · 845 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
package geeks.algo.sort;
public abstract class Sort{
String type;
String timeComplexity;
String spaceComplexity;
int[] arr;
Sort(int[] arr){
this.arr=arr;
}
abstract protected void performSort();
abstract protected void setComplexities();
void display(){
System.out.println("\nSorting type is "+type);
System.out.print("Sorted Array... ");
for(int i=0;i<this.arr.length;i++){
System.out.print(this.arr[i]+" ");
}
System.out.println();
System.out.println("Time Complexity: "+timeComplexity+". Space Complexity: "+spaceComplexity+".");
}
void performTask(){
long startTime = System.nanoTime();
performSort();
long endTime = System.nanoTime();
long diff = endTime - startTime;
setComplexities();
display();
System.out.println("Total time taken to sort (in Nanoseconds): "+diff);
}
}