Title Address
https://pta.patest.cn/pta/test/15/exam/4/question/720
5-12 sort (25 points)
Given N-N (Long integer range) integers, the output is required to be sorted from small to large.
This two parts is used to test the performance of a variety of different sorting algorithms in various data situations. The test data of each group are characterized as follows:
- Data 1: only 1 elements;
- Data 2:11 A different integer, test the basic correctness;
- Data 3:103 random integers;
- 4:104 random integers of data;
- 5:105 random integers of data;
- Data 6:105 sequential integers;
- Data 7:105 inverse integers;
- Data 8:105 basic ordered integers;
- Data 9:105 random positive integers, not exceeding 1000 per digit.Input format:
Enter the first line to give a positive integerNN (\le 10^5≤10? ) 5?? ), followed by a line that gives aninteger of n n (in the range of long integers), separated by a space.
Output format:Output from small to large in a row, the numbers are separated by 1 spaces, and there is no extra space at the end of the line.
Input Sample:114 981 10 -17 0 -20 29 50 8 43 -5
Sample output:-20 -17 -5 0 4 8 10 29 43 50 981
The question is to help you with the timing.
/* An integer in the range of nn (long integer) that requires the output to be sorted from small to large. This two parts is used to test the performance of a variety of different sorting algorithms in various data situations. The test data of each group are as follows: Data 1: only 1 elements; data 2:11 different integers, test the basic correctness; Data 3:103 random integers, 4:104 random integers, data 5:105 random integers, data 6:105 sequential integers, data 7:105 reverse integers ; Data 8:105 basic ordered integers, data 9:105 random positive integers, each number does not exceed 1000. The problem itself is used to compare the speed of the sorting algorithm, but with the fast-line comprehensive level is very fast. I'm done. The result of the quick row time result score Topic compiler spents (ms) memory (MB) User 2017-07-05 21:16 answer correct 255-12gcc522 test point results Test point results Score/out of Use (MS) memory (MB) test point 1 answer correct 1/ 111 Test point 2 answer correct 10/1021 test point 3 answer correct 2/221 test point 4 answer correct 2/271 test point 5 answer correct 2/2492 test point 6 answer correct 2/2522 test point 7 answer correct 2/2472 test point 8 answer correct 2/2412 test point 9 answer correct 2/ 2471 another, the cutoff from 3 to 100 after the speed slightly faster some evaluation results time results score Topic compiler spents (ms) memory (MB) User 2017-07-05 21:20 answer correct 255-12gcc482 test point result test point result score/ Out of Time (ms) memory (MB) test point 1 answer correct 1/121 test point 2 answer correct 10/1021 test point 3 answer correct 2/221 test point 4 answer correct 2/281 test point 5 answer correct 2/2482 test point 6 answer correct 2/2392 test point 7 answer correct 2/ 2412 Test point 8 answer correct 2/2422 test point 9 answer correct 2/2441 results of result evaluation result time result score Topic compiler spents (ms) memory (MB) User 2017-07-05 21:19 answer correct 255-12gcc79152 test point result score/full time (ms) memory (MB) test point 1 answer correct 1/121 test point 2 answer correct 10/1021 test point 3 answer correct 2/221 test point 4 answer correct 2/ 2261 Test point 5 answer correct 2/234952 test point 6 answer correct 2/2402 test point 7 answer correct 2/279152 test point 8 answer correct 2/2632 test point 9 answer correct 2/235871*/#include <stdio.h># Define CUTOFF 100int t[100000];void swap (int *a,int *b) {int temp;temp=*a;*a=*b;*b=temp;} int median3 (int a[],int left,int right) {//printf ("Median3 got%d as left,%d as right\n", left,right); int middle= (Left+righ T)/2;if (A[left]>a[right]) swap (&a[left],&a[right]), if (A[left]>a[middle]) swap (&a[left],&a[ Middle]), if (A[middle]>a[right]) swap (&a[middle],&a[right]); swap (&a[middle],&a[right-1]);// printf ("Median3 got%d as a pivot,middle=%d\n", a[right-1],middle); return a[right-1];} void Insertionsort (int a[],int left, int. right) {int i,j,temp;for (i=left;i<right;i++) {temp=a[i+1];for (j=i+1;j> left;j--) {if (temp<a[j-1]) A[j]=a[j-1];else break;} A[j]=temp;}} void quicksort (int a[],int left,int right) {int low,high,pivot;low=left;high=right-1;if (Right-left<=cutoff) { Insertionsort (a,left,right); return;} PIVOT=MEDIAN3 (A,left,right), while (1) {while (A[++low]<pivot), while (A[--high]>pivot), if (Low
PTA 09-Sort 1 Sort (25 points)