Comparison of insert sort and hill sort

Source: Internet
Author: User

Hill sort is an upgrade of the inserted sort, the insertion sort is the nearest comparison, and until the end, the hill sort is a jumping comparison, if the two difference is a large number distance, so the effect of the hill sort is revealed.

//Insert Sort
function Insertsort (arr) {var j = 0; for (var i = 1; I<arr. length; i++) {var temp= Arr[i]; var k= i; While (k>= 0 && arr[k-1] >= temp) {Arr[k] = arr[k-1]; k--; j + +; } Arr[k] = temp; } console.log (J, ' compare Times ') return arr; }//Hill sort var p = 0; function Shellsort (arr, gaps) {for (var g = 0; G<Gaps. length; ++g) {for (var i= Gaps[g];i < arr.length; ++i) {var temp= Arr[i]; var J= i; For (; J>= Gaps[g] && arr[j-gaps[g]] > temp; J-= Gaps[g]) {Arr[j] = arr[j-gaps[g]]; p++; } Arr[j] = temp; }} console.log (P, ' compare Times ') return arr; }

Comparison of insert sort and hill sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.