mirror of
https://github.com/wahyd4/java-sorting.git
synced 2026-08-09 04:46:05 +10:00
s
This commit is contained in:
-1091
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<connections/>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<connection>
|
||||
<connection>
|
||||
<name>Default</name>
|
||||
<source>file:/home/junv</source>
|
||||
</connection>
|
||||
</connection>
|
||||
@@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sites/>
|
||||
@@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<servers/>
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20,1,6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
//首先进行分组
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
//对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0 ; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
|
||||
for (j = outer; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
|
||||
for (int inner = outer; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] array = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
|
||||
for (j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
//data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
int length = data.length;
|
||||
for(int gap = length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < length; i++){
|
||||
int temp = data[i];
|
||||
|
||||
for(j = i; j >= gap && temp<data[j - gap]; j= j-gap){
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && data[i] < data[j - gap]; j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
// data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0 ; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
System.out.println("array["+(i+d)+"]"+array[i+d]+"****array["+i+"]"+array[i]);
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len; i=i+d) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 1, 6, 3, 19, 7, 14, 5, 60, 29, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
//获取数组长度
|
||||
int length = data.length;
|
||||
// 首先进行分组,每次组中元素大致为之前2倍。
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
// 对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j
|
||||
- gap) {
|
||||
//缓存下表最大的那个数
|
||||
int temp = data[j];
|
||||
//将两数交换位置,将较大数保存到下标最大的位置。
|
||||
data[j] = data[j - gap];
|
||||
data[j - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int temp : array){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
System.out.println("array["+(i+d)+"]="+array[i+d]+" array["+i+"]="+array[i]);
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
System.out.println("array["+(i+d)+"]="+array[i+d]+"****array["+i+"]="+array[i]+"***");
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 1, 6, 3, 19, 7, 14, 5, 60, 29, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
// 首先进行分组,每次所分组为之前2倍。
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
// 对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j
|
||||
- gap) {
|
||||
//缓存下表最大的那个数
|
||||
int temp = data[j];
|
||||
//将两数交换位置,将较大数保存到下标最大的位置。
|
||||
data[j] = data[j - gap];
|
||||
data[j - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
public static void shellSort(Comparable[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap /= 2){
|
||||
for(int i = gap; i < data.length; i++){
|
||||
Comparable temp = data[i];
|
||||
for(j = i; j >= gap && temp.compareTo(data[j - gap]) < 0; j -= gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
|
||||
|
||||
shellSort(data);
|
||||
System.out.println();
|
||||
|
||||
for(int i = 0; i < data.length; i++)
|
||||
System.out.print(data[i] + " ");
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap = gap / 2){
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j -= gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] array = { 16, 20, 6, 3, 19, 7, 14, 5, 10 };
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap /= 2){
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j -= gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
|
||||
|
||||
shellSort(data);
|
||||
System.out.println();
|
||||
|
||||
for(int i = 0; i < data.length; i++)
|
||||
System.out.print(data[i] + " ");
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d > 1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array, int len) {
|
||||
int d = len;
|
||||
while (d > 1) {
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12, 10,8};
|
||||
Another.shellSort(testArray, 10);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
|
||||
for (int i = 0; i < len - (d+1); i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
|
||||
for (int i = 0; i < len - d-1; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
if(d%2 ==0){
|
||||
d =(d / 2);
|
||||
}
|
||||
|
||||
for (int i = 0 ; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
int length = data.length;
|
||||
for(int gap = length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < length; i++){
|
||||
int temp = data[i];
|
||||
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap /= 2){
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j -= gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] array = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 1, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
// 首先进行分组
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
// 对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j
|
||||
- gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d > 1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
int length = data.length;
|
||||
for(int gap = length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < length; i++){
|
||||
int temp = data[i];
|
||||
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] array = { 16, 20, 6, 3, 19, 7, 14, 12, 10 };
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println("****************************");
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len; i=i+d) {
|
||||
if (array[i].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
System.out.println("array["+(i+d)+"]="+array[i+d]+"****array["+i+"]="+array[i]);
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0 ; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
|
||||
for (int inner = outer; inner >= gap && data[inner] < data[inner- gap]; inner = inner- gap) {
|
||||
|
||||
int temp = data[inner];
|
||||
data[inner] = data[inner - gap];
|
||||
|
||||
data[inner-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d > 1) {
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12, 10};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20,1, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
//首先进行分组
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
//对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && data[i] < data[j - gap]; j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 };
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap /= 2){
|
||||
for(int i = gap; i < data.length; i++){
|
||||
Comparable temp = data[i];
|
||||
for(j = i; j >= gap && temp.compareTo(data[j - gap]) < 0; j -= gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
|
||||
|
||||
shellSort(data);
|
||||
System.out.println();
|
||||
|
||||
for(int i = 0; i < data.length; i++)
|
||||
System.out.print(data[i] + " ");
|
||||
}
|
||||
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
System.out.println("array["+(i+d)+"]"+array[i+d]+"****array["+i+"]"+array[i]+"***");
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0 ; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 1, 6, 3, 19, 7, 14, 5, 60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
// 首先进行分组
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
// 对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j
|
||||
- gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0 ; i <=len-d; i=i+d) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len-d; i=i+d) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0 ; i < len; i=i+d) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
int length = data.length;
|
||||
for(int gap = length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 1, 6, 3, 19, 7, 14, 5, 60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
// 首先进行分组,每次所分组为之前2倍。
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
// 对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j
|
||||
- gap) {
|
||||
//缓存下表最大的那个数
|
||||
int temp = data[j];
|
||||
//将较大数保存到下标最大的位置。
|
||||
data[j] = data[j - gap];
|
||||
data[j - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >= 1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d > 1) {
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12, 10,8};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && data[i] < data[j - gap]; j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
int length = data.length;
|
||||
for(int gap = length/ 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 1, 6, 3, 19, 7, 14, 5, 60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
// 首先进行分组,每次所分组为之前2倍。
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
// 对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j
|
||||
- gap) {
|
||||
//缓存下表最大的那个数
|
||||
int temp = data[j];
|
||||
|
||||
data[j] = data[j - gap];
|
||||
data[j - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static void shellSort(Comparable[] data){
|
||||
int j;
|
||||
for(int gap = data.length / 2; gap > 0; gap /= 2){
|
||||
for(int i = gap; i < data.length; i++){
|
||||
Comparable temp = data[i];
|
||||
for(j = i; j >= gap && temp.compareTo(data[j - gap]) < 0; j -= gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
Random r = new Random();
|
||||
Comparable[] data = new Comparable[20];
|
||||
for(int i = 0; i < data.length; i++){
|
||||
data[i] = r.nextInt(data.length);
|
||||
}
|
||||
|
||||
for(int i = 0; i < data.length; i++)
|
||||
System.out.print(data[i] + " ");
|
||||
|
||||
shellSort(data);
|
||||
System.out.println();
|
||||
|
||||
for(int i = 0; i < data.length; i++)
|
||||
System.out.print(data[i] + " ");
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
System.out.println("array["+(i+d)+"]="+array[i+d]+" array["+i+"]="+array[i]);
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
System.out.println("array["+(i+d)+"]="+array[i+d]+" array["+i+"]="+array[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = a;
|
||||
while (d > 1) {
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12, 10,8};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
|
||||
for (int inner = outer; inner >= gap && data[inner] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && temp < data[j - gap]; j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >= 1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
int temp = data[i];
|
||||
|
||||
for (j = i; j >= gap && data[i] < (data[j - gap]); j = j - gap) {
|
||||
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
System.out.println("array["+(i+d)+"]"+array[i+d]+"****array["+i+"]"+array[i]+"***");
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
|
||||
for (j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i < len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
System.out.println("执行次数为:"+(len-d));
|
||||
}
|
||||
|
||||
System.out.println("****************************");
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d/ 2);
|
||||
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
System.out.println("array["+(i+d)+"]="+array[i+d]+" array["+i+"]="+array[i]);
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
|
||||
for (int inner = outer; inner >= gap && data[inner] < data[inner- gap]; inner = inner- gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
for (int inner = outer; inner >= gap
|
||||
&& data[inner] < data[inner - gap]; inner = inner - gap) {
|
||||
|
||||
int temp = data[inner];
|
||||
data[inner] = data[inner - gap];
|
||||
|
||||
data[inner - gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >= 1) {
|
||||
System.out.println("d========" + d);
|
||||
if (d % 2 == 0) {
|
||||
d = (d / 2);
|
||||
} else {
|
||||
d=(d+1)/2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = { 1, 20, 6, 3, 19, 7, 14, 12, 70, 18, 40, 30, 25,
|
||||
29 };
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20,1, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
//首先进行分组
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
//对每个组进行插入比较
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
|
||||
int length = data.length;
|
||||
//首先进行分组
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int i = gap; i < length; i++) {
|
||||
|
||||
|
||||
for (int j = i; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class ShellSort {
|
||||
|
||||
// 定义需要排序的数组
|
||||
private static int[] array = { 1, 20, 6, 3, 19, 7, 14, 12, 10 };
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10,9 ,80,70,60,29,30,40};
|
||||
|
||||
public static void shellSort(int[] data){
|
||||
int j;
|
||||
int length = data.length;
|
||||
for(int gap = data.length / 2; gap > 0; gap = gap / 2){
|
||||
|
||||
for(int i = gap; i < data.length; i++){
|
||||
int temp = data[i];
|
||||
for(j = i; j >= gap && temp<(data[j - gap]); j= j-gap){
|
||||
data[j] = data[j - gap];
|
||||
}
|
||||
|
||||
data[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
shellSort(data);
|
||||
for(int flag :data){
|
||||
System.out.print(flag+" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i = 0; i <len-d; i++) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
System.out.println("执行次数为:"+(len-d));
|
||||
}
|
||||
|
||||
System.out.println("****************************");
|
||||
for(T temp : array){
|
||||
System.out.print(temp +" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
// 定义需要排序的数组
|
||||
private static int[] data = { 16, 20, 6, 3, 19, 7, 14, 5, 10, 9, 80, 70,
|
||||
60, 29, 30, 40 };
|
||||
|
||||
public static void shellSort(int[] data) {
|
||||
int j;
|
||||
int length = data.length;
|
||||
for (int gap = length / 2; gap > 0; gap = gap / 2) {
|
||||
|
||||
for (int outer = gap; outer < length; outer++) {
|
||||
|
||||
|
||||
for (int inner = outer; j >= gap && data[j] < data[j - gap]; j = j - gap) {
|
||||
|
||||
int temp = data[j];
|
||||
data[j] = data[j - gap];
|
||||
|
||||
data[j-gap] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
shellSort(data);
|
||||
for (int flag : data) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >=1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (int)(d / 2);
|
||||
for (int i =0; i < len; i=i+d) {
|
||||
if (array[i+d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29,11,21};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
public class Another {
|
||||
|
||||
public static <T extends Comparable<? super T>> void shellSort(T[] array) {
|
||||
int len = array.length;
|
||||
int d = len;
|
||||
while (d >1) {
|
||||
System.out.println("d========"+d);
|
||||
d = (d + 1) / 2;
|
||||
for (int i = 0; i < len - d; i++) {
|
||||
if (array[i + d].compareTo(array[i]) < 0) {
|
||||
T temp = array[i + d];
|
||||
array[i + d] = array[i];
|
||||
array[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer[] testArray = {1, 20, 6, 3, 19, 7, 14, 12,70,18,40,30,25,29};
|
||||
Another.shellSort(testArray);
|
||||
System.out.println("The result is:");
|
||||
for (Integer item : testArray) {
|
||||
System.out.print(item);
|
||||
System.out.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user