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 ;}