zoukankan      html  css  js  c++  java
  • 例20:希尔排序

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 void ShellSort(int *pArray,int nCount)
     5 {
     6      int gap = nCount/2;
     7      while(gap >= 1)
     8      {
     9                for(int i = gap; i<nCount;i++)
    10                {
    11                        int j = 0;
    12                        int tmp = pArray[i];
    13                        for(j = i-gap; j>=0&&tmp<pArray[j]; j-=gap)
    14                        {
    15                                pArray[j+gap] = pArray[j];
    16                        }
    17                        pArray[j+gap] = tmp;
    18                }
    19                gap /= 2;
    20      }
    21 }
    22 
    23 int main()
    24 {
    25     int nCount,pArray[20];
    26     while(~scanf("%d",&nCount)&&nCount)
    27     {
    28                                        for(int i = 0;i<nCount&&i<20;i++)
    29                                        {
    30                                                scanf("%d",&pArray[i]);
    31                                        }
    32                                        ShellSort(pArray,nCount);
    33                                        for(int i = 0;i<nCount&&i<20;i++)
    34                                        {
    35                                                printf("%d ",pArray[i]);
    36                                        }
    37                                        printf("
    ");
    38     }
    39     return 0;
    40 }
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 void ShellSort(int *pArray,int nCount)
     5 {
     6      int gap = nCount/2;
     7      while(gap >= 1)
     8      {
     9                for(int i = gap; i<nCount;i++)
    10                {
    11                        int j = 0;
    12                        int tmp = pArray[i];
    13                        for(j = i-gap; j>=0&&tmp<pArray[j]; j-=gap)
    14                        {
    15                                pArray[j+gap] = pArray[j];
    16                        }
    17                        pArray[j+gap] = tmp;
    18                }
    19                gap /= 2;
    20      }
    21 }
    22 
    23 int main()
    24 {
    25     int nCount,pArray[20];
    26     while(~scanf("%d",&nCount)&&nCount)
    27     {
    28                                        for(int i = 0;i<nCount&&i<20;i++)
    29                                        {
    30                                                scanf("%d",&pArray[i]);
    31                                        }
    32                                        ShellSort(pArray,nCount);
    33                                        for(int i = 0;i<nCount&&i<20;i++)
    34                                        {
    35                                                printf("%d ",pArray[i]);
    36                                        }
    37                                        printf("
    ");
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    LibSVM文本分类之工程中调用LibSVM进行文本分类
    交叉验证–Cross validation
    SkySeraph博主的GLCM特征学习
    Libsvm分类步骤
    VC技巧
    转载 libsvm vc 移植 实现多类分类
    FANN学习2之建立简单工程
    开源库FANN学习笔记1
    忙了一上午终于把形状特征搞定了啊
    终于看到结果了
  • 原文地址:https://www.cnblogs.com/FWFC/p/6282491.html
Copyright © 2011-2022 走看看