ACM-quick sorting

Source: Internet
Author: User

Fast sorting time limit (Common/Java): 1000 MS/3000 MS running memory limit: 65536 KByte
Total submissions: 653 pass the test: 297

Description

 

Specify the number of input sorting elements n and the corresponding n elements, write the program, use the quick sorting algorithm in the inner Sorting Algorithm to sort, and output the corresponding sequence of the final sorting result.

 

Input

 

There are two rows in total. The first row gives n number of sorting elements, the second row gives n elements, 1 ≤ n ≤ 100000, and each element value range is)

 

Output

 

Output the sorting result in one row.

 

Sample Input

7
48 36 68 72 12 48 2

Sample output

2 12 36 48 48 68 72

Prompt

Data structure A Experiment 4

Question Source

CHENZ

 

// Quick sorting # include <iostream> using namespace std; int * l; void Swap (int & a, int & B) {int temp = a; a = B; B = temp;} int Partition (int left, int right) {int I = left, j = right + 1; do {do I ++; while (l [I] <l [left]); do j --; while (l [j]> l [left]); if (I <j) swap (l [I], l [j]);} while (I <j); Swap (l [left], l [j]); return j ;} void QuickSort (int left, int right) {if (left <right) {int j = Partition (left, right); QuickSort (left, J-1); QuickSort (j + 1, right) ;}} int main () {int N, I; cin >> N; l = new int [N]; for (I = 0; I <N; I ++) cin> l [I]; QuickSort (0, N-1); for (I = 0; I <N; I ++) {cout <l [I]; if (I <N-1) cout <""; // here oj format requirements} return 0 ;}

 

 

 

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.