//shell sort with insert sort
functionShell_insert_sort (arr) {varGap =arr.length; Do{Gap= parseint (GAP/3) + 1;Console.log (GAP); for(vari = gap; i < arr.length; i+=Gap) { varTMP =Arr[i]; for(varj = I-gap; J >= 0 && tmp < ARR[J]; J-=Gap) {Arr[j+ Gap] =Arr[j]; } arr[j+GAP] =tmp; } } while(Gap > 1); }//shell sorting with Exchange sortingfunctionShell_bubble_sort (arr) {Gap=arr.length; varFlag =true; Do{Gap= parseint (GAP/3) + 1; Flag =true; for(vari = 0; I < arr.length && flag; i + =Gap) {Flag=false; Console.log (arr) for(varj = 0; J < arr.length-i-gap; J + =Gap) { if(Arr[j] > arr[j +Gap]) {Swap (arr, J, J+gap); Flag=true; } } } } while(Gap > 1);}functionswap (arr, I, j) {varTMP =Arr[i]; Arr[i]=Arr[j]; ARR[J]=tmp;}vararr = [1, 99, 23, 88, 56, 77, 3];shell_bubble_sort (arr);//Shell_insert_sort (arr)Console.log (arr);
JS Implementation Shell Sort