PTA sort

PTA sorting (25 points)
Given N integers (in the range of long integers), it is required to output the results sorted from small to large.

This question aims to test the performance of various sorting algorithms in various data situations. The characteristics of each group of test data are as follows:

Data 1: Only 1 element;
Data 2: 11 different integers, the test is basically correct;
Data 3: 103 random integers;
Data 4: 104 random integers;
Data 5: 105 random integers;
Data 6: 105 sequential integers;
data 7: 105 reverse-order integers;
data 8: 105 basically ordered integers;
data 9: 105 random positive integers, each number does not exceed 1000.
Input format: The
first line of input gives a positive integer N (≤10^5), and the following line gives N integers (in the range of long integers), separated by spaces.

Output format:
output the results sorted from small to large in one line, separated by 1 space between numbers, and no extra spaces are allowed at the end of the line.

Input sample:

11
4 981 10 -17 0 -20 29 50 8 43 -5

Sample output:

-20 -17 -5 0 4 8 10 29 43 50 981

Problem-solving code

#include<algorithm>//快速排序头文件 
#include<iostream>
using namespace std;
int main()
{
    
    
	int n;
	cin>>n;
	int a[n],i;
	for(i=0;i<n;i++)
	{
    
    
		cin>>a[i];
	 } 
	 sort(a,a+n);//快速排序 
	 for(i=0;i<n-1;i++)
	 {
    
    
	 	cout<<a[i]<<' ';
	 }
	 cout<<a[n-1];
	 return 0;
}

Since fast sorting is used, the general sorting is fast sorting, and in general, fast sorting can be used.

Big guys are welcome to advise. If you don’t understand, you can comment or add Q2651877067. If you see it, you will reply as soon as possible! ! !

Guess you like

Origin blog.csdn.net/mmmjtt/article/details/113944555