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

📄 折半插入排序.cpp

📁 共有10个文件代码
💻 CPP
字号:
#include<iostream.h>
#include<iomanip.h>
void Binsertsort(int A[],int n)
{
	int i,j,low,high,mid,x,p;
	for(i=1;i<n;i++)
	{
		low=0;high=i-1;
		x=A[i];
		while(low<=high)
		{
			mid=(low+high)/2;
			if(x<A[mid])
				high=mid-1;
			else
				low=mid+1;
		}
		p=low;
		for(j=i-1;j>=p;j--)
			A[j+1]=A[j];
		A[p]=x;
	}
}
void main()
{
	int A[10],s,n=10;
	cout<<"请输入要求排序的无序序列(10个数据):";
	for(s=0;s<n;s++)
		cin>>A[s];
	cout<<"折半插入排序"<<endl<<"排序前:";
	for(s=0;s<n;s++)
		cout<<setw(3)<<A[s];
	cout<<endl;
	Binsertsort(A,n);
	cout<<"排序后:";
	for(s=0;s<n;s++)
		cout<<setw(3)<<A[s];
	cout<<endl;
}

⌨️ 快捷键说明

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