Algorithmic Heights第14题:2-Way Partition

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值