当前位置:网站首页>Likou Brush Question Record--Common Functions
Likou Brush Question Record--Common Functions
2022-08-09 02:05:00 【@baigui】
目录
一、快速排序
//快速排序算法
void quick_sort(vector<int>& nums,int start,int end)
{
if(start < end)
{
//常规变量
int i;
//
int base=nums[start];//in order to sort the array0个元素为base
int left=start;//左指针
int right=end;//右指针
while(left<right)
{
//从右向左找,比base大,right--
while(left<right&&nums[right]>=base)
{
right--;
}
//找比base校,替换left所在位置的数字
nums[left]=nums[right];
//从左向右找,比base小,left++
while(left<right&&nums[left]<=base)
{
left++;
}
//比base大,替换right所在位置的数字
nums[right]=nums[left];
}
nums[left]=base;//此时left=right,用base替换这个位置的数字
// for(i=0;i<=4;i++)
// std::cout<<" i in "<<nums[i]<<std::endl;
//递归调用
quick_sort(nums,start,left-1);
quick_sort(nums,left+1,end);
}
}
边栏推荐
猜你喜欢
Data recovery software EasyRecovery supports recovery of all types of files
Group DETR:分组一对多匹配是加速DETR收敛的关键
全文翻译:EDPB关于VVA(虚拟语音助理)中处理个人数据的指南02/2021
The last exam before the NPDP revision!caution
Mysql 5.7 into the pit
全文翻译:EDPB数据保护影响评估(DPIA:Data Protection Impact Assessment)指南
力扣刷题记录5.1-----59. 螺旋矩阵 II
HNUMSC-C语言第一课
MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions
Wireshark packet capture tool
随机推荐
Go-7-RESTful API的设计
德语翻译器在线翻译中文
LeetCode每日一题:搜索插入位置 (均1200道)方法:二分查找
软件测试技术之如何编写测试用例(5)
D. Tournament Countdown
LeetCode每日两题01:二分查找 (均1200道)
解决有路由策略的情况下域内NAT不通的问题
Wireshark packet capture tool
How to install yii2
The server quit without updating PID file (/usr/local/mysql/data/localhost.pid).
Likou Brush Question Record 8.1-----206. Reverse linked list
JDBC technology (1) - a simple JDBC test
项目经理VS产品经理,二者到底有何不同?
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
全文翻译:EDPB 基于设计和默认的数据保护指南
显著性检验--学习笔记
2020.12.4 log
年金险的安全性怎么样啊?可靠吗?
eladmin容器部署超详细过程
js实现数组去重的方式(7种)