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

📄 binasort(折半插入排序).cpp

📁 折半插入排序 一种排序的方法
💻 CPP
字号:
// binasort(折半插入排序).cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<assert.h>

using namespace std;

typedef struct node
{
	int key;
	int oth;
}node;

void binasort(node r[],int n);
int _tmain(int argc, _TCHAR* argv[])
{
	  	node s[11];
	ifstream infile("D:\\1.txt");
	assert(infile);
	for(int i=1;i<11;i++)
		infile>>s[i].key;
	ofstream outfile("D:\\1.txt",ios_base::app);
	assert(outfile);
	
	binasort(s,10);
	outfile<<endl;
	for(int i=1;i<11;i++)
		outfile<<s[i].key<<' ';
	outfile<<endl;
	return 0;
}

void binasort(node r[],int n)
{
	int i,j;
	int l,h,mid;
	for(i=2;i<=n;i++)
	{
		r[0]=r[i];
		l=1;h=i-1;
		while(l<=h)
		{
			mid=(l+h)/2;
			if(r[0].key<r[mid].key) h=mid-1;
			else l=mid+1;
		}
		for(j=i-1;j>=l;j--)r[j+1]=r[j];
		r[l]=r[0];
	}
}

⌨️ 快捷键说明

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