当前位置:网站首页>Unable to climb hill sort, directly insert sort
Unable to climb hill sort, directly insert sort
2022-07-01 22:54:00 【Old fish 37】
Sorry for breaking the final exam for so long , From today on, an average of one high-quality article is output every day for everyone to enjoy !!!
First:
Direct insert sort :InsertSort
Holistic thinking :
Complete code implementation :
// Direct insert sort
void InsertSort(int* arr, int len)
{
for (int i = 0; i < len - 1; i++)
{
int end = i;
int tmp = arr[end + 1];
while (end >= 0)
{
if (tmp < arr[end])
{
arr[end + 1] = arr[end];
--end;
}
else
{
break;
}
}
arr[end + 1] = tmp;
}
}
void PrintSort(int* arr, int len)
{
for (int i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
}
int main()
{
int arr[] = { 3,1,2,4,9,5,6};
int len = sizeof(arr) / sizeof(arr[0]);
InsertSort(arr, len);
PrintSort(arr, len);
}
The following is about how you once ignored him , Now you can't afford Hill sort
Hill sort is an optimization of direct insert sort
Holistic thinking :
1、 Pre sort --- Turn data into data that is about to be sorted
step : Divide into groups first gap, And then we can sort it
When gap arrive 1 It's sorted when
Isn't that amazing
Summarize the characteristics of hill sorting :
Complete code implementation :
// Shell Sort
void ShellSort(int* arr, int len)
{
int gap = len;
while (gap > 1)
{
gap = gap / 3 + 1;// Make sure the last number is 1
for (int i = 0; i < len - gap; i++)
{
int end = i;
int tmp = arr[end + gap];
while (end >= 0)
{
if (tmp < arr[end])
{
arr[end + gap] = arr[end];
end -= gap;
}
else
{
break;
}
}
arr[end + gap] = tmp;
}
}
}
void PrintSort(int* arr, int len)
{
for (int i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
}
int main()
{
int arr[] = { 3,1,2,4,9,5,6};
int len = sizeof(arr) / sizeof(arr[0]);
ShellSort(arr, len);
PrintSort(arr, len);
}
Guys, hurry up and operate the machine !!!
If there is a mistake , Your advice are most welcome !
边栏推荐
- 正则系列之量词(Quantifiers)
- Metauniverse may become a new direction of Internet development
- 深度学习--数据操作
- 14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
- [untitled]
- 【扫盲】机器学习图像处理中的深层/浅层、局部/全局特征
- # CutefishOS系统~
- Appium自动化测试基础 — 补充:Desired Capabilities参数介绍
- Pytorch nn.functional.unfold()的简单理解与用法
- Measurement of reference loop gain and phase margin
猜你喜欢
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 release | geek headlines
Yolov5.5 call local camera
14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
Single step debugging analysis of rxjs observable of operator
正则系列之量词(Quantifiers)
2020-ViT ICLR
MySQL中对于索引的理解
正则系列之组和范围(Groups and Ranges)
MySQL中对于事务的理解
隐藏用户的创建和使用
随机推荐
转--原来gdb的底层调试原理这么简单
pytorch训练自己网络后可视化特征图谱的代码
人体姿态估计的热图变成坐标点的两种方案
恶意软件反向关闭EDR的原理、测试和反制思考
Origin2018安装教程「建议收藏」
Flink SQL command line connection yarn
cvpr2022 human pose estiamtion
Lc669. Prune binary search tree
Reprint CSDN article operation
Digital currency: far-reaching innovation
深度学习--数据操作
思科考试--路由的概念和配置考试
Flynk SQL client uses comparison and is familiar with official documents
【c语言】malloc函数详解[通俗易懂]
SAP 智能机器人流程自动化(iRPA)解决方案分享
el-input文本域字数限制,超过显示变红并禁止输入
Operation category read is not supported in state standby
【无标题】
Kubernetes create service access pod
业务可视化-让你的流程图'Run'起来