当前位置:网站首页>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
边栏推荐
- Alibaba sentinel学习QA
- Three minutes to teach you to use Houdini fluid > > to solve particle fluid droplets
- The displayed amount of ABAP ALV is inconsistent with the exported amount
- Complete color conversion formulas and conversion tables (31 kinds)
- SAP self created table log function is enabled
- MySQL -- the secret of lock -- how to lock data
- String self generated code within a given range
- Mysql database backup and recovery under Linux (full + incremental)
- 【编程实践/嵌入式比赛】嵌入式比赛学习记录(二):基于TCP的图片流传输
- SAP GUI安全性
猜你喜欢

Cloud computing skills competition -- the first part of openstack private cloud environment

CTF攻防世界刷题51-

《内网安全攻防:渗透测试实战指南》读书笔记(八):权限维持分析及防御

三星,再次“西征”

Buuctf misc brush questions

Intranet penetration series: icmpsh of Intranet tunnel

Feign源码分析

Go语学习笔记 - 异常处理 | 从零开始Go语言

数据库之Mysql——概述安装篇

Upload labs range practice
随机推荐
BUUCTF MISC刷題
CTF攻防世界刷题51-
Upload labs range practice
内网渗透系列:内网隧道之pingtunnel
MySQL--锁的奥秘--数据怎么锁
《内网安全攻防:渗透测试实战指南》读书笔记(六):域控制器安全
GUI,CLI与Unix哲学
CSV Column Extract列提取
nacos源码分析思路
C read INI file and write data to INI file
CTF attack and defense world brush questions 51-
Attack and defense world misc questions 1-50
内网渗透系列:内网隧道之icmptunnel(DhavalKapil师傅的)
KCD_ EXCEL_ OLE_ TO_ INT_ Convert reports an error sy subrc = 2
LeetCode15. 三数之和
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
一些关于网络安全的好教程或笔记的链接,记录一下
数据库之MySQL——基础篇
Go语学习笔记 - Slice、Map | 从零开始Go语言
SAP sto with billing process and configuration