package com.csdhsm.sort; /** * @Title: ShellSort.java * @Package: com.csdhsm.sort * @Description å¸å°æåº * @author Han * @date 2016-4-3 ä¸å5:04:01 * @version V1.0 */ public class ShellSort { public void sort(int[] arr,int len){ /** * æ¥é¿é»è®¤ä¸ºé¿åº¦/2 */ int gap = len/2; /** * 彿¥é¿gap为1æ¶,ç»ææåº */ while(gap >= 1){ // æè·ç¦»ä¸º gap çå ç´ ç¼ä¸ºä¸ä¸ªç»ï¼æ«æææç» for(int i = gap;i < len;i ++){ int temp = arr[i]; int j = 0; // 对è·ç¦»ä¸º gap çå ç´ ç»è¿è¡æåº for(j = i-gap;j >= 0 && temp < arr[j];j = j-gap){ arr[i] = arr[j]; } arr[j + gap] = temp; } //åå°å¢é gap = gap / 2; } } }