当前位置:网站首页>Quick sort code implementation
Quick sort code implementation
2022-07-25 06:17:00 【Can't fail I】
Quick sort

In the following example , Select the last element 40 As a median .i Used to traverse the subscript of the array ;k Representation ratio 40 The subscript of the small element to be saved

int Partition(int* arr, int left, int right) {
int k, i;
for (i = k = left; i < right; i++) {
if (arr[i] < arr[right]) {
swap(arr[k], arr[i]);
k++;
}
}
swap(arr[k], arr[right]);
return k;
}
// Recursive implementation of quick sorting
void QuickSort(ElemType A[], int low, int high) {
if (low < high) {
int pivotpos = Partition(A, low, high);// The elements to the left of the split point are smaller than the split point , The elements on the right of the split point are larger than the split point
QuickSort(A, low, pivotpos - 1);
QuickSort(A, pivotpos + 1, high);
}
}
边栏推荐
- leetcode/二进制加法
- node.express中req.body总是undefind解决
- (15)[驱动开发]过写拷贝
- Amazoncaptcha 95%成功率绕过亚马逊IP验证码
- Leetcode/ binary addition
- Qunhui NPV Suite (NPV server) Download
- R奇怪语法总结
- Prometheus operator configures promethesrule alarm rules
- Dry goods | training AI model can't find data? Collect 20 selected open source communities!
- 【C语言】指针和数组的深入理解(第一期)
猜你喜欢

深度解析:2022年最火的商业模式链动2+1,是合法模式吗?

HTB-Arctic

Unity model simplification / consolidation one click plug-in

Unity Animator动画与状态机

(牛客多校二)G-Link with Monotonic Subsequence(构造题)

剑指 Offer 45. 把数组排成最小的数

The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell

【Unity3D】UGUI回调函数

【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口

2022 "strong country Cup" preliminary WP (with script and detailed process)
随机推荐
Unity Animator动画与状态机
[unity3d] ugui callback function
Typedef usage and template
深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
How to play a data mining game entry Edition
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
Req.body in node.express is always undefind
Brief tutorial of vbs script syntax (1)
【datawhale202207】强化学习:强化学习基础
剑指 Offer 36. 二叉搜索树与双向链表
(2022牛客多校二)L-Link with Level Editor I(动态规划)
Baidu SEM bidding avoidance
Context must be a dict rater solution
Codeforces Round #809 (Div. 2)
Sword finger offer 45. arrange the array into the smallest number
日期(DAY 76)
How to troubleshoot the problem of too many inodes
[daily practice] day (14)
GF Securities online account opening? Is it safe?
mysql 查询当前数据库下的表名