C language-Fast sorting algorithm

Source: Internet
Author: User

1. Fast Sorting algorithm
1#include <stdio.h>2 3 structnode4 {5     intkey;6 };7typedefstructnode DataType;8 9 intQukpass_sort (DataType ar[],intSintt);Ten intQuk_sort (DataType ar[],intSintt); One  A intMainvoid) - { -  the     intn,i; -DataType array[ -]; -  -printf"Input The length of the array <<20>:"); +scanf"%d",&n); -      for(i=0; i<n; i++)//Input Array +     { Aprintf"Input%d datas:", i+1); atscanf"%d",&array[i]); -     } -  -  -printf"\ n The array is:"); -      for(i=0; i<n; i++) in     { -printf"%4d", Array[i]);//the input array is displayed to     } +  -Quk_sort (Array,0, N-1);//Call Sort Algorithm the  *  $printf"\ n The array after quicksort is:");Panax Notoginseng      for(i=0; i<n; i++)//output-sorted algorithm results -     { theprintf"%4d", Array[i]); +  A     } the     return(0); + } -  $  $ intQuk_sort (DataType ar[],intSintT//Fast Sorting algorithm - { -     inti; the     if(s<t) -     {WuyiI=Qukpass_sort (ar,s,t); theQuk_sort (ar,s,i-1); -Quk_sort (ar,i+1, T); Wu  -     } About } $  -  - intQukpass_sort (DataType ar[],intSintT//One-time division algorithm for fast sorting - { A DataType temp; +     intLow,high; the  -Low=s;//Low is the left boundary of the sequence when divided $high=t;//High is the left edge of the sequence when divided theTemp=ar[s];//to temporarily store the median axis value in temp the      while(low<High ) the     { the          while((Low//leave the sorting code greater than the middle axis on the right sub-sequence -high--; in         if(Ar[high].key<temp.key)//move a sort code that is less than or equal to the middle axis to the left the         { thear[low]=Ar[high]; Aboutlow++; the         } the          while((Low//move less than the middle axis sort code to the left thelow++; +         if(Temp.key<ar[low].key)//move greater than sort code to the right -         { thear[high]=Ar[low];Bayihigh--; the         } the     } -Ar[low]=temp;//put the mid-axis value in the correct position -     return(low); the}

C language-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.