当前位置:网站首页>力扣刷题记录--常用功能函数
力扣刷题记录--常用功能函数
2022-08-09 01:51:00 【@白圭】
目录
一、快速排序
//快速排序算法
void quick_sort(vector<int>& nums,int start,int end)
{
if(start < end)
{
//常规变量
int i;
//
int base=nums[start];//以要进行排序数组第0个元素为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);
}
}
边栏推荐
猜你喜欢
33. 分别谈谈联合索引生效和失效的条件
Image denoising based on edge enhancement Diffusion 】 (cEED) and Coherence Enhancing coursing together (cCED) filter to realize image denoising matlab code
LeetCode精选200道--双指针篇
知识图谱学习笔记——我的第一次知识图谱实践
Wireshark packet capture tool
[C language brush questions] Application of fast and slow pointers in linked lists
The Best Open Source Web Application Firewall to Protect Your Web Applications
LeetCode每日一题:搜索插入位置 (均1200道)方法:二分查找
Group DETR:分组一对多匹配是加速DETR收敛的关键
torchversion.transforms的使用
随机推荐
方法参数
数字孪生+燃气管理,开启智慧燃气管理新模式
如何准备一份简历
Grid布局介绍
PostMan import certificate add certificate
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
Wireshark抓包工具
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
Using ngrok on Raspberry Pi (Extra 2)
The 7 taboos of time management summarized by the postgraduate students, how many have you won?
软件测试的调用接口怎么调用,逻辑是什么?
torchversion.transforms的使用
ONNX是什么?怎么用?[简明解读版]
spdlog日志库的封装使用
Bugs encountered in remote control projects
【信号去噪】基于Sage-Husa自适应卡尔曼滤波器实现海浪磁场噪声抑制及海浪磁场噪声的产生附matlab代码
RF调试过程中现象一
seaborn 笔记: 绘制分类数据
Go-9-数据类型-函数
Observer pattern