-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.java
More file actions
executable file
·70 lines (52 loc) · 1.27 KB
/
Shell.java
File metadata and controls
executable file
·70 lines (52 loc) · 1.27 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.*;
public class Shell{
int[] list;
public Shell(int length){
list = new int[length];
}
public void swap(int i,int j){
int temp;
temp=this.list[i];
this.list[i]=this.list[j];
this.list[j]=temp;
}
public void print(){
for (int el : this.list ) {
System.out.print(el+",");
}
System.out.println();
}
public void shell(){
int inc=this.list.length/2;
while(inc>=1)
{
for (int si=0;si<inc;si++) {
this.insertion(si,inc);
}
inc=inc/2;
}
this.print();
}
public void insertion(int si,int inc){
for (int i=si;i<this.list.length ;i+=inc) {
for(int j=Math.min(i+inc,this.list.length-1);j-inc>=0;j-=inc){
if(this.list[j]<this.list[j-inc]){
this.swap(j,j-inc);
}else{
break;
}
}
}
}
public static void main(String arg[]){
Scanner s= new Scanner(System.in);
System.out.println("Please enter the size");
int n = s.nextInt();
Shell sh=new Shell(n);
for(int i=0;i<n;i++)
{
sh.list[i]=s.nextInt();
}
sh.shell();
}
}