Skip to content

Commit 93b1ee2

Browse files
author
Jonas
committed
add a few comments to shellsort.java
1 parent bf3c7c5 commit 93b1ee2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sorting/ShellSort/java/ShellSort.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ public class ShellSort{
33
public static int[] shellSort(int arr[]){
44
int temp;
55
int n = arr.length;
6+
// Gap of size n/2 initially
67
for(int i = n/2; i>0; i=i/2){
78
for(int j = i; j<n; j++){
89
for(int k=j-i;k>=0;k=k-i){
10+
// break loop if is higher, if not switch
911
if(arr[k+i]>=arr[k]){
1012
break;
1113
}else{
@@ -30,14 +32,13 @@ public static void main(String[] args) {
3032
}
3133
System.out.println();
3234

33-
sortedArray = shellSort(array);
34-
35+
// shell sort
36+
sortedArray = shellSort(array);
3537
System.out.println("After: ");
3638
n = sortedArray.length;
3739
for (int i = 0; i < n; ++i) {
3840
System.out.print(sortedArray[i] + " ");
3941
}
4042
System.out.println();
4143
}
42-
43-
}
44+
}

0 commit comments

Comments
 (0)