⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shellsort.cpp

📁 包含8种常用的排序。如快速排序
💻 CPP
字号:
#include <iostream.h>
#include <stdio.h>
#include <time.h>
#include<stdlib.h>
#include <algorithm>
using namespace std;
#define N 10000
int a[N];

void ShellSort()
{
	int i,j,d,k,m;
	d=N/2;
	while(d>0)
	{
		for(i=0;i<d;i++)
		{
			for(j=i;j<N;j=j+d)
			{
				m=a[j];
				for(k=j-d;k>=0;k=k-d)
				{
					if (m>a[k]) break;
					a[k+d]=a[k];
				}
				a[k+d]=m;
			}
		}
		d=d/2;
	}
	for(i=0;i<N-1;i++)
	{cout<<a[i]<<"->";}
    cout<<a[i]<<"\n";

}

void main()
{  
   int k;
   clock_t start=clock();/*程序开始运行的时间*/

   //srand((unsigned)time(NULL));//随时间的不同产生不同的随机数
   for(k=0;k<N;k++)
		a[k]=rand()%N+1;
   ShellSort();

   clock_t end=clock();/*程序结束运行的时间*/
   cout<<"整个程序运行的时间为:";
   cout<<(end-start)<<"毫秒\n";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -