赞
踩
- #include <stdio.h>
- void print(int k[],int n);
- void shellsort(int k[],int n);
- int main(){
- int K[]= {49,38,97,76,65,13,27,50};
- shellsort(K,8);
- print(K,8);
- }
- //希尔排序法
- void shellsort(int k[],int n){
- int i,j,gap=n;
- int temp,flag;
- while(gap>1){
- gap=gap/2;
- do{
- flag=0;//每趟排序前,标志flag置为0
- for(i=0;i<n-gap;i++){
- j=i+gap;
- if(k[i]>k[j]){
- temp=k[i];
- k[i]=k[j];
- k[j]=temp;
- }
- }
- }while(flag!=0);
-
- }
- }
- void print(int k[],int n){
- for (int i=0;i<n;i++){
- printf("%d\n",k[i]);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。