当前位置:网站首页>Hill | insert sort
Hill | insert sort
2022-07-06 21:20:00 【2021CAT】
#include <bits/stdc++.h>
using namespace std;
const int in = 0.000001;
const double PI = 3.1415926535;
#define inf 0x3f3f3f;
typedef long long ll;
const int N = 1e5 + 10;
int q[N];
void Shell_sort (int a[], int n)
{
int d, i, j;
for (d = n / 2; d >= 1; d /= 2) // d Represents each increment , from n / 2 until d = 1 When d = 1 when This is also known as insertion sorting , This is done to optimize the insertion sort , Avoid when the number of inserts is small , It will cause multiple backward shifts .
for (i = d / 2; i < n; i ++)
{
if (a[i] < a[i - d]) // If a[i] Less than It corresponds to the previous hour of increment , Record a[i]
{
int x = a[i];
for (j = i - d; j >= 0 && x < a[j]; j -= d) // Find smaller ones in incremental order
{
a[j + d] = a[j]; // still a[i] < a[j] Move back to x Make room
}
a[j + d] = x; // Finally insert x
}
}
}
int main ()
{
int n;
cin >> n;
for (int i= 0; i < n; i ++) scanf ("%d", &q[i]);
Shell_sort (q, n);
for (int i = 0; i < n; i++)
i != n - 1 ? printf("%d ", q[i]) : printf("%d", q[i]);
return 0;
}
边栏推荐
- js中,字符串和数组互转(一)——字符串转为数组的方法
- 基于深度学习的参考帧生成
- 技术分享 | 抓包分析 TCP 协议
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- c#使用oracle存储过程获取结果集实例
- @PathVariable
- Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
- Start the embedded room: system startup with limited resources
- string的底层实现
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
猜你喜欢
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Set up a time server
PHP saves session data to MySQL database
Why do job hopping take more than promotion?
Is it profitable to host an Olympic Games?
Deployment of external server area and dual machine hot standby of firewall Foundation
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
Manifest of SAP ui5 framework json
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
随机推荐
R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
Regular expression collection
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
数据湖(八):Iceberg数据存储格式
Fastjson parses JSON strings (deserialized to list, map)
基于深度学习的参考帧生成
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
Data Lake (VIII): Iceberg data storage format
Interviewer: what is the internal implementation of ordered collection in redis?
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
Description of web function test
分糖果
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
It's almost the new year, and my heart is lazy
C # use Oracle stored procedure to obtain result set instance
VIM basic configuration and frequently used commands
OSPF multi zone configuration
js之遍历数组、字符串
每个程序员必须掌握的常用英语词汇(建议收藏)