import
java.util.Arrays;
public
class
Sort {
public
static
void
bubbleSort(
int
[] arrays)
{
for
(
int
i=
0
;i<arrays.length-
1
;i++)
{
for
(
int
j=
1
;j<arrays.length-i;j++)
{
if
(arrays[j-
1
]>arrays[j])
{
int
temp=arrays[j-
1
];
arrays[j-
1
]=arrays[j];
arrays[j]=temp;
}
}
}
}
public
static
void
selectSort(
int
[] arrays)
{
for
(
int
i=
0
;i<arrays.length-
1
;i++)
{
int
ind=i;
for
(
int
j=i+
1
;j<arrays.length;j++)
{
if
(arrays[j]<arrays[ind])
{
ind=j;
}
}
if
(ind!=i)
{
int
temp=arrays[ind];
arrays[ind]=arrays[i];
arrays[i]=temp;
}
}
}
public
static
void
insertSort(
int
[] arrays)
{
for
(
int
i=
1
;i<arrays.length;i++)
{
int
temp=arrays[i];
int
ind=i;
for
(
int
j=i-
1
;j>=
0
;j--)
{
if
(temp<arrays[j])
{
arrays[j+
1
]=arrays[j];
ind=j;
}
else
{
break
;
}
}
arrays[ind]=temp;
}
}
public
static
void
quickSot(
int
[] arrays,
int
left,
int
right)
{
if
(left>=right)
{
return
;
}
int
compInd=left;
int
i=left;
int
j=right;
while
(i<j)
{
for
(;j>=i;j--)
{
if
(arrays[j]<arrays[compInd])
{
int
temp=arrays[j];
arrays[j]=arrays[compInd];
arrays[compInd]=temp;
compInd=j;
break
;
}
}
for
(;i<=j;i++)
{
if
(arrays[i]>arrays[compInd])
{
int
temp=arrays[i];
arrays[i]=arrays[compInd];
arrays[compInd]=temp;
compInd=i;
break
;
}
}
}
quickSot(arrays,left,compInd-
1
);
quickSot(arrays,compInd+
1
,right);
}
public
static
int
[] merger(
int
[] a,
int
[] b)
{
int
[] result=
new
int
[a.length+b.length];
int
ind=
0
;
int
ind1=
0
;
int
ind2=
0
;
while
(ind1<a.length && ind2<b.length)
{
if
(a[ind1]<b[ind2])
{
result[ind++]=a[ind1++];
}
else
{
result[ind++]=b[ind2++];
}
}
while
(ind1<a.length)
{
result[ind++]=a[ind1];
ind1++;
}
while
(ind2<b.length)
{
result[ind++]=b[ind2];
ind2++;
}
return
result;
}
public
static
void
shellSort(
int
[] arrays,
int
[] steps)
{
for
(
int
step:steps)
{
for
(
int
i=
0
;i<step;i++)
{
for
(
int
j=i;j<arrays.length;j+=step)
{
int
ind=j;
for
(
int
k=j+step;k<arrays.length;k+=step)
{
if
(arrays[k]<arrays[ind])
{
ind=k;
}
}
if
(ind!=j)
{
int
temp=arrays[ind];
arrays[ind]=arrays[j];
arrays[j]=temp;
}
}
}
}
}
public
static
void
main(String[] args) {
int
[] a=
new
int
[]{
6
,
3
,
13
,
8
,
5
,
10
,
12
,
16
,
4
,
6
};
shellSort(a,
new
int
[]{
5
,
3
,
1
});
System.out.println(Arrays.toString(a));
}
}