forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shell_Sort.java
47 lines (34 loc) · 886 Bytes
/
Shell_Sort.java
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
package Sorting;
public class shell {
public static void main(String args[])
{
int[] a={9, 8, 3, 56, 5, 6, 4, 1};
int length=a.length;
int gap=length/2;
// System.out.println(gap);
while(gap>0)
{
for(int i=gap;i<length;i++)
{
int temp=a[i];
// System.out.println((temp));
int j=i;
// System.out.println((j));
while(j>=gap && a[j-gap]>temp)
{
// System.out.println(a[j]);
a[j]=a[j-gap];
// System.out.println(a[j]);
j=j-gap;
a[j]=temp;
// System.out.println(a[j]);
}
}
gap=gap/2;
}
for(int i=0;i<length;i++)
{
System.out.println(a[i]);
}
}
}