C language, c

Source: Internet
Author: User

C language, c
1. Fast Sorting Algorithm

1 # include <stdio. h> 2 3 struct node 4 {5 int key; 6}; 7 typedef struct node DataType; 8 9 int Qukpass_sort (DataType Ar [], int s, int t ); 10 int Quk_Sort (DataType Ar [], int s, int t); 11 12 int main (void) 13 {14 15 int n, I; 16 DataType array [20]; 17 18 printf ("Input the length of the array <20>:"); 19 scanf ("% d", & n); 20 for (I = 0; I <n; I ++) // Input array 21 {22 printf ("Input % d datas:", I + 1); 23 scanf ("% d ", & array [I]); 24} 25 26 27 printf ("\ n The array are:"); 28 for (I = 0; I <n; I ++) 29 {30 printf ("% 4d", array [I]); // The input array is 31} 32 33 Quk_Sort (array, 0, n-1 ); // call The Sorting Algorithm 34 35 36 printf ("\ n The array after quicksort are:"); 37 for (I = 0; I <n; I ++) // output the sorted algorithm result 38 {39 printf ("% 4d", array [I]); 40 41} 42 return (0 ); 43} 44 45 46 int Quk_Sort (DataType Ar [], int s, int t) // fast Sorting Algorithm 47 {48 int I; 49 if (s <t) 50 {51 I = Qukpass_sort (Ar, s, t); 52 Quk_Sort (Ar, s, I-1); 53 Quk_Sort (Ar, I + 1, t ); 54 55} 56} 57 58 59 int Qukpass_sort (DataType Ar [], int s, int t) // a division algorithm for quick sorting 60 {61 DataType temp; 62 int low, high; 63 64 low = s; // low indicates the left boundary 65 high = t of the sequence during partitioning; // high indicates the left boundary 66 temp = Ar [s] of the sequence during partitioning. // Save the central axis value to temp67 while (low 

 

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.