Java Learning notes-sorting algorithm of hill sort (Shell sort)

Source: Internet
Author: User

The head of the Sunset Building, the voice of the hung, Jiangnan wandering. The Wu hook to see, the railing shot all over, no one will, boarding meaning.

--Deng Jiankang and Heart Pavilion

The hill algorithm is a sort algorithm proposed by Hill (D.l.shell) in 1959. is one of the first time complexity breakthrough O (N2) algorithms.

It is based on the insertion sort.

On the code:

1  Public classShellsort {2 3      Public Static voidShellsort (int[] arr) {4         5         intincrement =arr.length;6         intTemp//Card7         inti;8         intJ;9          Do {Tenincrement = increment/3+1;//Incremental One              for(i = increment; i < arr.length; i++) { A                 if(Arr[i] < arr[i-Increment]) { -temp =Arr[i]; -                      for(j = i-increment; J >=0&& temp < ARR[J]; J-=increment) { theARR[J] =arr[j]^arr[j +increment]; -Arr[j + increment] =arr[j]^arr[j +increment]; -ARR[J] =arr[j]^arr[j +increment]; -                     } +                 } -             } +} while(Increment >1); A     } at}

Delta Pick k = 2^ (t-k+1)-1 (0≤k≤t≤?log2 (n+1)?)

Java Learning notes-sorting algorithm of hill sort (Shell sort)

Related Article

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.