Skip to content

Commit 4a640b0

Browse files
authored
Update ShellSort.java
1 parent e4fba59 commit 4a640b0

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

ShellSort.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1-
public class ShellSort
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class ShellSort {
2+
public static void main(String[] args) {
53
int a[]={25,-17,8,92,-21,0};
64

7-
for(int gap=a.length/2;gap>0;gap/=2)
8-
{
9-
10-
for(int i=gap;i<a.length;i++)
11-
{
5+
for(int gap=a.length/2;gap>0;gap/=2) {
6+
for(int i=gap;i<a.length;i++) {
127
int tmp=a[i];
138
int j=i;
149

15-
while(j>=gap &&a[j-gap]>tmp)
16-
{
10+
while(j>=gap &&a[j-gap]>tmp) {
1711
a[j]=a[j-gap];
1812
j-=gap;
1913
}
2014
a[j]=tmp;
21-
2215
}
2316
}
24-
25-
System.out.println("Sorted Array : ");
26-
System.out.print("[");
27-
for(int i=0;i<a.length;i++)
28-
{
29-
if(i == a.length-1)
30-
System.out.print(a[i]);
31-
else
32-
System.out.print(a[i] + ", ");
17+
18+
System.out.println("Sorted Array : ");
19+
System.out.print("[");
20+
21+
for(int i=0;i<a.length;i++) {
22+
if(i == a.length-1)
23+
System.out.print(a[i]);
24+
else
25+
System.out.print(a[i] + ", ");
3326
}
3427
System.out.println("]");
3528
}
36-
37-
}
29+
}

0 commit comments

Comments
 (0)