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

推荐订阅源

NISL@THU
NISL@THU
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Cloudbric
Cloudbric
H
Heimdal Security Blog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
A
Arctic Wolf
W
WeLiveSecurity
SecWiki News
SecWiki News
S
Security Affairs
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
P
Privacy & Cybersecurity Law Blog
AWS News Blog
AWS News Blog
T
The Exploit Database - CXSecurity.com
V2EX - 技术
V2EX - 技术
AI
AI
Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
有赞技术团队
有赞技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
H
Hacker News: Front Page
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
月光博客
月光博客
博客园 - 【当耐特】
Recorded Future
Recorded Future
O
OpenAI News
Hacker News: Ask HN
Hacker News: Ask HN
Scott Helme
Scott Helme
N
News and Events Feed by Topic
Help Net Security
Help Net Security
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
小众软件
小众软件

博客园 - 柏放

检测移动设备横竖屏 [转]一句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
--;
        }
    }
}