标签:logs shell insert data 希尔排序 change 希尔 nbsp exchange
1 public class Solution 2 { 3 public void shellSort(int[] data) 4 { 5 for(int i = data.length / 2; i > 0; i = i / 2) 6 { 7 for(int j = 0; j < i; j ++) 8 { 9 insertSort(data, j, i); 10 } 11 } 12 } 13 14 public void insertSort(int[] data, int begin, int distance) 15 { 16 for(int i = begin + distance; i < data.length; i = i + distance) 17 { 18 for(int j = i - distance; j >= 0; j = j - distance) 19 { 20 if(data[j] > data[j + distance]) 21 { 22 exchange(data, j, j + distance); 23 } 24 else 25 { 26 break; 27 } 28 } 29 } 30 } 31 32 public void exchange(int[] data, int m, int n) 33 { 34 int memory = data[m]; 35 data[m] = data[n]; 36 data[n] = memory; 37 } 38 }
标签:logs shell insert data 希尔排序 change 希尔 nbsp exchange
原文地址:http://www.cnblogs.com/StringBuilder/p/7461176.html