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