当前位置:网站首页>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);
}
}
边栏推荐
- 解决有路由策略的情况下域内NAT不通的问题
- HCIP-R&S By Wakin自用笔记(2)OSPF之OSPF回顾、虚连接
- LeetCode每日一题:搜索插入位置 (均1200道)方法:二分查找
- 显著性检验--学习笔记
- Use of torchversion.transforms
- Grid布局介绍
- [机缘参悟-65]:《兵者,诡道也》-6-孙子兵法解读-并战计
- Cmake 报错 Could not find a package configuration file provided by “OpenCV“
- MT4/MQ4L入门到精通EA教程第二课-MQL语言常用函数(二)-账户信息常用功能函数
- 力扣刷题记录6.1-----203. 移除链表元素
猜你喜欢
随机推荐
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
torchversion.transforms的使用
[深入研究4G/5G/6G专题-55]: L3信令控制-4-软件功能与流程的切分-CU网元的信令
解决有路由策略的情况下域内NAT不通的问题
MT4/MQL4入门到精通EA课程第二课-常用的功能函数
智能视频监控设计摄像头部分
Phenomenon 1 during RF debugging
如何在群晖系统中安装cpolar(群晖6.X版)
字节输入流(InputStream)与字节输出流(OutputStream)
Mysql 5.7 into the pit
[机缘参悟-65]:《兵者,诡道也》-6-孙子兵法解读-并战计
史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!
The 7 taboos of time management summarized by the postgraduate students, how many have you won?
Difference between KQL and Lucene
composer的使用记录
配置文件的读取-TOML
Grid布局介绍
多语种翻译-免费多语种翻译软件
MT4/MQL4 entry to proficient foreign exchange EA tutorial Lesson 1 Getting to know MetaEditor
New Swagger3.0 tutorial, OAS3 quick configuration guide, to automate API interface documentation!









