Partition an array around an interger
Partition an array of integers around a value such taht all elements less than x come before elements greater than or equal to x.
Idea: Just use of subroutine PARTION of quicksort() with a slight modification.
array[start, end] to be partitioned around value x.
We need to additional pointers i and j, to maintain an invariant, which is true at all times:
array[start, i] stores elements less than x
array[i+1, j-1] stores elements greater than or equal to x
array[j, end] stores elements which haven't been explored yet.

void Partition(A, start, end){
int i = start - 1;
for(int j = start; j <= end; ++j){
if(A[j] < x){
i++;
swap A[i] with A[j];
}
}
}
Partition an array around an interger的更多相关文章
- Lintcode: Partition Array
Given an array "nums" of integers and an int "k", Partition the array (i.e move ...
- Partition Array
Given an array nums of integers and an int k, partition the array (i.e move the elements in "nu ...
- [Swift]LeetCode1013. 将数组分成和相等的三个部分 | Partition Array Into Three Parts With Equal Sum
Given an array A of integers, return true if and only if we can partition the array into three non-e ...
- LeetCode 1013 Partition Array Into Three Parts With Equal Sum 解题报告
题目要求 Given an array A of integers, return true if and only if we can partition the array into three ...
- Partition Array Into Three Parts With Equal Sum LT1013
Given an array A of integers, return true if and only if we can partition the array into three non-e ...
- LeetCode 1043. Partition Array for Maximum Sum
原题链接在这里:https://leetcode.com/problems/partition-array-for-maximum-sum/ 题目: Given an integer array A, ...
- 【leetcode】1043. Partition Array for Maximum Sum
题目如下: Given an integer array A, you partition the array into (contiguous) subarrays of length at mos ...
- 【leetcode】1020. Partition Array Into Three Parts With Equal Sum
题目如下: Given an array A of integers, return true if and only if we can partition the array into three ...
- 【LeetCode】1020. Partition Array Into Three Parts With Equal Sum 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- Servlet & JSP - Form-based Authentication
基本认证和摘要认证都只能使用浏览器自带的登录框而不能使用自定义的登录页面.如果必须使用自定义的登录页面,则可以选择基于表框的认证方式. 基于表框的认证的配置与基本认证和摘要认证的差别在于部署描述符中 ...
- Linux 命令 - id: 显示用户的身份标识
命令格式 id [OPTION]... [USERNAME] 命令参数 -a 忽略,仅为与其他版本相兼容而设计. -Z, --context 仅显示当前用户的安全环境. -g, --group 仅显示 ...
- Linux - 文件的压缩与归档
文件压缩 常用的压缩命令有 gzip.bzip2 等. gzip 命令 命令格式 gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ] 命令参数 -c ...
- unity3d所要知道的基础知识体系大纲,可以对照着学习,不定期更新
本文献给,想踏入3D游戏客户端开发的初学者. 毕业2年,去年开始9月开始转作手机游戏开发,从那时开始到现在一共面的游戏公司12家,其中知名的包括搜狐畅游.掌趣科技.蓝港在线.玩蟹科技.天神互动.乐元素 ...
- 风云CM - 算法分析 & genkey实现
// 风云CM分析 // 计算用户名 00402D8A |> \8D45 F8 LEA EAX, [LOCAL.2] 00402D8D |. 50 PUSH EAX 00402D8E |. E8 ...
- JavaScript学习笔记(12)——JavaScript自定义对象
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- (转)Linux下tomcat JVM内存设置步骤
java.lang.OutOfMemoryError: PermGen space java.lang.OutOfMemoryError: Java heap space -------------- ...
- 【Qt】关于Qt【转】
什么是Qt Qt是一个针对桌面.嵌入式.移动设备的一个跨平台的应用程序开发框架,支持的平台包括Linux.OS X.Windows.VxWorks.QNX.Android.iOS.BlackBerry ...
- [总结]Android系统体系结构
Android 从图中可以看出Android主要的组成部分,其中底层是Linux的内核,包括的主要就是文件.内存.系统资源等的管理,Google在这部分的工作主要就是电源管理和一部分驱动,并且整合上层 ...
- Redis的PHP操作手册
String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...