Data Structure --- implement Hill sorting in C Language

Source: Internet
Author: User

Data Structure --- implement Hill sorting in C Language

// Shell Sort // Yang Xin # include

 
  
# Include

  
   
Void ShellSort (int a [], int length) {int increment; int I, j; int temp; for (increment = length/2; increment> 0; increment/= 2) // used to control the step size, and finally decreases to 1 {// I is arranged starting from step. It should be the first element to be inserted for sorting. // you can not move it first, sort for (I = increment; I <length; I ++) {temp = a [I]; for (j = I-increment; j> = 0 & temp <a [j]; j-= increment) {a [j + increment] = a [j];} a [j + increment] = temp; // fill in the first position }}} int main () {printf (==================== Hill sort ========================); int I, j; int a [] = {5, 18,151,138,160, 63,174,169, 79,200}; printf (the sequence to be sorted is:); for (I = 0; I <10; I ++) {printf (% d, a [I]);} ShellSort (a, 10); printf (the sorted sequence is:); for (j = 0; j <10; j ++) {printf (% d, a [j]);} printf (); return 0 ;}

  

 

 

 

 

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.