当前位置:网站首页>Quick rehearsal exercise
Quick rehearsal exercise
2022-04-23 08:05:00 【Pen drawing Acacia】
function sort(array) {
if (!checkArray(array)) return
quickSort(array, 0, array.length - 1);
return array;
}
function quickSort(array, left, right) {
if (left < right) {
swap(array, , right)
// Random value , Then swap with the end , This is slightly less complex than taking a fixed position
let indexs = part(array, parseInt(Math.random() * (right - left + 1)) + left, right);
quickSort(array, left, indexs[0]);
quickSort(array, indexs[1] + 1, right);
}
}
function part(array, left, right) {
let less = left - 1;
let more = right;
while (left < more) {
if (array[left] < array[right]) {
// The current value is smaller than the reference value ,`less` and `left` All plus one
++less;
++left;
} else if (array[left] > array[right]) {
// The current value is larger than the reference value , Swap the current value with the value on the right
// And don't change `left`, Because the current value has not been judged
swap(array, --more, left);
} else {
// Same as the reference value , Move subscript only
left++;
}
}
// Exchange the reference value with the first value larger than the reference value
// So the array becomes `[ Less than the reference value , At baseline , Greater than the benchmark value ]`
swap(array, right, more);
return [less, more];
}
版权声明
本文为[Pen drawing Acacia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624332763.html
边栏推荐
- 内网渗透系列:内网隧道之icmpsh
- Go语学习笔记 - Slice、Map | 从零开始Go语言
- Go语学习笔记 - 语言接口 | 从零开始Go语言
- NLLLoss+log_SoftMax=CE_Loss
- [programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
- Buuctf misc brush questions
- [NLP notes] preliminary study on CRF principle
- Chapter IV intangible assets
- strcat()、strcpy()、strcmp()、strlen()
- Move layout (Flex layout, viewport label)
猜你喜欢

upload-labs 靶场练习

CSV Column Extract列提取
![[unity VFX] Introduction notes of VFX special effects - spark production](/img/bb/a6c637d025dfb8877e6b85e7f39d6b.png)
[unity VFX] Introduction notes of VFX special effects - spark production

Go语学习笔记 - 数组 | 从零开始Go语言

《内网安全攻防:渗透测试实战指南》读书笔记(五):域内横向移动分析及防御

第七章 资产减值
![BUUCTF [ACTF2020 新生赛]Include1](/img/47/b8f46037f7e9476b8e01e8d6a7857a.png)
BUUCTF [ACTF2020 新生赛]Include1

The displayed amount of ABAP ALV is inconsistent with the exported amount

第四章 无形资产

云计算技能大赛 -- openstack私有云环境 第一部分
随机推荐
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
sentinel集成nacos动态更新数据原理
Three minutes to teach you to use Houdini fluid > > to solve particle fluid droplets
Série de pénétration Intranet: icmpsh du tunnel Intranet
GUI,CLI与Unix哲学
三星,再次“西征”
LeetCode 1611. 使整数变为 0 的最少操作次数
MySQL--锁的奥秘--数据怎么锁
RAID0和RAID5的创建和模拟RAID5工作原理
内网渗透系列:内网隧道之icmptunnel(jamesbarlow师傅的)
Essays (updated from time to time)
Using lambda expression to solve the problem of C file name sorting (whether it is 100 or 11)
Redis事务实现乐观锁原理
Talk about the essence of interface idempotent and consumption idempotent
SAP sto with billing process and configuration
Cloud computing skills competition -- Part 2 of openstack private cloud environment
Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
SAP tr manual import system operation manual
《内网安全攻防:渗透测试实战指南》读书笔记(五):域内横向移动分析及防御
C # control the camera, rotate and drag the observation script (similar to scenes observation mode)