Problem
A partition procedure is an essential part of the Quick Sort algorithm, the subject of one of the following problems. Its main goal is to put the first element of a given array to its proper place in a sorted array. It can be implemented in linear time, by a single scan of a given array. Moreover, it is not hard to come up with an in-place algorithm.
分区过程是快速排序算法的重要组成部分,它是以下问题之一的主题。它的主要目的是将给定数组的第一个元素放在排序数组中的适当位置。通过对给定阵列的单次扫描,可以在线性时间内实现。此外,不难提出就地算法。
Given: A positive integer and an array of integers from to .
Return: A permuted array such that it is a permutation of and there is an index such that for all , , and for all .
给定:正整数 和一个数组 来自的整数 至 。
返回:排列数组 这样它是 并且有一个索引 这样 对全部 , 和 对全部 。
Sample Dataset
9
7 2 5 6 1 3 9 4 8
Sample Output
5 6 3 4 1 2 7 9 8