Blue Bridge Cup practice (a foundation)

Basic training 01 the number of columns to sort

Problem Description
  Given a length n, the number of columns, this number of columns arranged in large ascending order. 1 <= n <= 200
Input Format
  Conduct a first integer n.
  The second line contains n integers, the number to be sorted, each of the integer absolute value of less than 10,000.
Output Format
  Output line, in ascending order of the number of output columns sorted.
 
Sample input
5
8 3 6 4 9
Sample Output
3 4 6 8 9
#include <the iostream> 
#include <Vector>
 the using  namespace STD; 

// quicksort (small to large) 
void QUICKSORT ( int left, int right, Vector < int > & ARR) 
{ 
    IF (left> = right)
         return ;
     int I, J, base ; 
    I = left, J = right;
     base = ARR [left];   // take the leftmost number of reference 
    the while (I < J) 
    { 
        the while (ARR [J]> = base && I < j)
            J - ;
         the while (ARR [I] <= Base && I < J) 
            I ++ ;
         IF (I < J) 
        { 
            int TEMP = ARR [I]; 
            ARR [I] = ARR [J]; 
            ARR [J ] = TEMP; 
        } 
    } 
    // reference number homing 
    ARR [left] = ARR [I]; 
    ARR [I] = base ;
     // recursive left 
    QUICKSORT (left, I- . 1 , ARR);
     // recursive the right
    quickSort(i+1, right, arr);
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);

    // 数据读入
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    // 快排
    quickSort(0, n-1, a);
    // 数据输出
    for(int i=0; i<n; ++i){
        cout << a[i];
        if(i != n-1){
            cout<< " ";
        }
    }
}

Personal summary :

  The study questions sorting algorithm, with bubbling wanted to do, but can not always think with bubble (he'll just write bubbling) it, and the time complexity is higher. The problem with fast row to do, emmm, right, read a lot of other people's data O (∩_∩) O ~ ha ha, before the data structure also taught full-back. (> Human <)

To Learn More :

  Quick sort: simply put, it is a number selected as the base to conduct a simple sort in a set of numbers such that the number of the base to the left than the small base (large) number to the right of the base than the large base (small), then the use of sub the idea of ​​the rule of two sequences around the base edge recursive operations, ultimately making the whole sequence order. Note that if the base is selected from the left, the right should search; if the selected base from the right, from the left to search.

  Gangster explain attached a fast row Bowen: https: //blog.csdn.net/qq_28584889/article/details/88136498

 

Guess you like

Origin www.cnblogs.com/DullRabbit/p/12555900.html