Hill sorting algorithm and fast sorting algorithm

Source: Internet
Author: User

The Hill sort source code is as follows:

#include <stdio.h>  //Hill sort void shellsort (int a[],int l, int r) {  



Quick sort the original code is as follows:

#include <stdio.h>//int a[16] = {10,7,12,25,8,9,11,71,82,90,1,14,99,7,456,1};//Quick sort subroutine int findpivot (int a[], int I,int j) {int firstkey = A[i];int k;for (k=i+1;k<=j;k++) if (A[k]>firstkey) return K;else if (A[k]<firstkey) return i;return-1;} Quick Sort subroutine int partition (int a[],int i,int j,int pivot) {int l,r;do{for (L = i;a[l]<pivot;l++); for (r = j;a[r]>=pivot;r) --); if (L < r) {int t = a[l]; a[l]=a[r];a[r]=t;}} while (l<=r); return l;} Quick Sort Main program void QuickSort (int a[],int i,int j) {int pivot;//datum divided by int k;//keyword is greater than or equal to pivot record in sequence starting subscript int Pivotindex;pivotin Dex = Findpivot (a,i,j), if (pivotindex!=-1) {//recursive termination condition pivot = A[pivotindex];k = partition (A,i,j,pivot); QuickSort (a,i,k-1 ); QuickSort (a,k,j);}     }//-----------------above is an implementation of quick sort-------------------////Quick Sort Improved version void Quick_sort (int s[], int l, int r) {if (L < R)        {int i = l, j = r, x = S[l];              while (I < J) {while (I < J && S[j] >= x) j--;  if (i < j) s[i++] = S[j];          while (I < J && S[i] < x) i++;        if (i < j) s[j--] = s[i];        } S[i] = x;         Quick_sort (S, l, i-1);    Quick_sort (S, i + 1, R); }}main () {int b[16] = {10,7,12,25,8,9,11,71,82,90,1,14,99,7,456,1};int length = sizeof (b)/sizeof (b[0]); QuickSort (b,0,  LENGTH-1); int i;for (i=0;i<length;i++) printf ("%d", B[i]);}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hill sorting algorithm and fast sorting algorithm

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.