惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
AWS News Blog
AWS News Blog
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
Attack and Defense Labs
Attack and Defense Labs
Jina AI
Jina AI
The Last Watchdog
The Last Watchdog
W
WeLiveSecurity
H
Help Net Security
V
Visual Studio Blog
宝玉的分享
宝玉的分享
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
Latest news
Latest news
T
Tor Project blog
I
Intezer
美团技术团队
GbyAI
GbyAI
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
Y
Y Combinator Blog
博客园 - 司徒正美
T
Tenable Blog
O
OpenAI News
N
News and Events Feed by Topic
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threatpost
Google Online Security Blog
Google Online Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
Help Net Security
Help Net Security

博客园 - 柏放

检测移动设备横竖屏 [转]一句css代码让你的网站变灰,一起悼念地震中逝去的生命! MYSQL命令行常用操作 MySQL数据库导入导出详解[转发] 国外达人收集的Cheet Sheet PHP学习:字符串操作和正则表达式 PHP学习:数组 PHP学习:文件操作 SQL Server:获得用户最新或前n条订单的几种SQL语句 SQL Server:APPLY表运算符 SQL Server:查询当前服务器有多少连接请求 SQL Server:关于Null的一些事 js倒计时 SQL Server:在Management Studio中使用Web浏览器 SQL Server:获得表的元数据 - SET FMTONLY ON SQL Server:把CSV文件导入到SQL Server表中 SQL Server:使用一个语句块插入多条记录 SQL Server:在事务中回滚TRUNCATE操作 Google Map API学习记录
排序:插入排序及希尔排序
柏放 · 2010-07-29 · via 博客园 - 柏放

代码

#include <stdio.h>
#define SIZE 11
void showarr(int[],int);
void insertsort(int [],int);
void insertsortV2(int [],int);
void shellsort(int [],int);
int main(void){
    
int arr[SIZE] = {0,10,4,7,2,1,8,32,20,80,6};
    
//insertsortV2(arr,SIZE);
    
//showarr(arr,SIZE);
    shellsort(arr,SIZE);
    
return 0;
}
void showarr(int arr[],int size){
    
int i;
    
for(i=1;i<size;i++){
        printf(
"%d,",arr[i]);
        
if(i == size -1){
            printf(
"\n");
        }
    }
}
void shellsort(int arr[],int size){
    
int n,i,j;
    printf(
"please input n:\n");
    
while(scanf("%d",&n) == 1 ){
        
if((n+1)<size){
            
for(i=n+1;i<size;i++){
                arr[
0= arr[i];
                j 
= i - n;
                
while((arr[0< arr[j]) && j>0){
                    arr[j
+n] = arr[j];
                    arr[j] 
= arr[0];
                    j 
= j-n;
                }
                
            }
            
//Show one times
            showarr(arr,size);            
        }
else{
            printf(
"n > size\n");
            printf(
"please input n:\n");
        }
    }
}
void insertsortV2(int arr[],int size){
    
int i,j;
    
for(i = 2;i<size;i++){
        arr[
0= arr[i];
        j 
= i-1;
        
while(arr[0< arr[j]){
            arr[j
+1= arr[j];
            arr[j] 
= arr[0];
            j
--;
        }
    }
}
void insertsort(int arr[],int size){
    
int i,j;
    
int temp;
    
for(i=1;i<size;i++){
        temp 
= arr[i];
        j 
= i-1;
        
while(temp<arr[j] && j >=0){
            arr[j
+1= arr[j];
            arr[j] 
= temp;
            j
--;
        }
    }
}