-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGnomeSort.java
More file actions
45 lines (31 loc) · 1004 Bytes
/
GnomeSort.java
File metadata and controls
45 lines (31 loc) · 1004 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
43
44
45
import java.util.Arrays;
public class GnomeSort {
String complexity;
GnomeSort() {
complexity = ". Quadratic Time Complexity.";
}
void sort(int[] sortArray) {
/*
Begin Time Start
*/
double start = (double) System.nanoTime();
int count = 0;
while (count < sortArray.length) {
if (count == 0 || sortArray[count] >= sortArray[count - 1]) {
count++;
}
else {
int tempInt = 0;
tempInt = sortArray[count];
sortArray[count] = sortArray[count - 1];
sortArray[count - 1] = tempInt;
count--;
}
}
/*
End Time
*/
double end = (double) System.nanoTime();
System.out.println("GnomeSort: " + Arrays.toString(sortArray) + complexity + " Seconds taken was " + ((end - start) / 1000000));
}
}