The Hill sort is an upgraded version of the Insert sort, which makes a great improvement on the basis of the insertion sort.
functionCArray (numelements) { This. DataStore = []; This. numelements =numelements; This. Prints =prints; This. SetData =SetData; This. gaps = [1750, 701, 301, 132, 57, 23, 10, 4, 1 ]; This. Swap =swap; This. Shellsort =Shellsort; This. Shellsort1 =Shellsort1; } //static interval sequence, Ciura sequence, the better interval sequence presented in the paper in 2001 functionSetData () { for(vari = 0; I < This. numelements; ++i) { This. datastore[i] =Math.floor (Math.random ()* ( This. numelements + 1)); } } functionswap (arr, index1, index2) {vartemp =ARR[INDEX1]; ARR[INDEX1]=Arr[index2]; ARR[INDEX2]=temp; } functionprints () { for(vari = 0; I < This. datastore.length; ++i) {document.write ( This. Datastore[i] + ""); if(i > 0 & i% 10 = = 0) {document.write ("<br/>"); } } } functionShellsort () { for(varg = 0; G < This. gaps.length; ++g) {varh = This. Gaps[g]; for(vari = h; I < This. datastore.length; ++i) {vartemp = This. Datastore[i]; for(varj = i; J >=h&& This. datastore[j-h] > This. Datastore[j]; J-=h) { This. datastore[j] = This. DATASTORE[J-h]; } This. datastore[j] =temp; } } } functionShellsort1 () {varN = This. Datastore.length; varH = 1; while(H < N/3) {//dynamically generating interval sequencesH = 3 * H + 1; } while(H >= 1) { for(vari = h; i < N; i++) { vartemp = This. Datastore[i]; for(varj = i; J >=h&& This. Datastore[j] < This. Datastore[j-h]; J-=h) { This. datastore[j] = This. DATASTORE[J-h]; } This. datastore[j] =temp; } h= (h-1)/3; } } varNumelements = 10000; varNums =NewCArray (numelements); Nums.setdata (); varStart =NewDate (). GetTime (); Nums.shellsort (); varStop =NewDate (). GetTime (); varElapsed = stop-start; document.write ("The hard coded interval sequence of the hill sort consumes the time:" + elapsed + "milliseconds. "); document.write ("<br/>"); varStart =NewDate (). GetTime (); Nums.shellsort1 (); varStop =NewDate (). GetTime (); varElapsed = stop-start; document.write ("The hard coded interval sequence of the hill sort consumes the time:" + elapsed + "milliseconds. ");
Advanced sorting algorithm--Hill sort (interval 1 o'clock is insert sort)