Data Structure sorting and searching in C Language
Data structure experiment sorting 1: Fast sorting
Time Limit: 1000 MS Memory Limit: 65536KB
Submit Statistic
Problem Description
Given an integer in the range of N long integers, you must output the results after a fast sorting with the first number in the given data as the pivot.
Input
Continuous input of multiple groups of data, each group of input data is given in the first row of a positive integer N (N <= 10 ^ 5), followed by N integers in the Long Integer Range, numbers are separated by spaces.
Output
Output the result of a quick sorting. The numbers are separated by a space. No extra space is allowed at the end of the row.
Example Input
8
49 38 65 97 76 13 27 49
Example Output
27 38 13 49 76 97 65 49
#include
int s[100010];void struff(int s[], int l, int r){ int i, j, key; i = l; j = r; key = s[i]; while(i < j) { while(i < j && s[j] >= key) j--; s[i] = s[j]; while(i < j && s[i] <= key) i++; s[j] = s[i]; } s[i] = key;}int main(){ int t, i; while(scanf("%d", &t) != EOF) { for(i = 0; i < t; i++) { scanf("%d", &s[i]); } struff(s, 0, t - 1); for(i = 0; i < t; i++) { if(i == 0) printf("%d", s[i]); else printf(" %d", s[i]); } printf("\n"); } return 0;}