3、冒泡排序BubbleSort()

//冒泡排序
#include
#include
#include
#include
#include
using namespace std;
const int MAXSIZE=501;//待排序数据规模,r[0]保留,实际数组是r[1]---r[500]
//冒泡排序BubbleSort()
void BubbleSort(int r[],int n)
{
	int exchange=n;
	int bound=0;
	int temp=0;//交换函数的暂存变量
	while(exchange!=0)
	{
		bound=exchange;
		exchange=0;
		for(int i=1;ir[i+1])//交换两者顺序
			{
				temp=r[i+1];
				r[i+1]=r[i];
				r[i]=temp;
				exchange=i;//一趟排序时最后交换的位置
			}				//在该位置之后都是排序好的
	}
}

//从外存data.txt读取数据至内存数组
void read_data(int data[])
{
	ifstream infile("data_salary.txt",ios::in);
	if(!infile)
	{
		cerr<<"open data_salary.txt error!"<>data[i];
	infile.close();
}
//输出内存数组至外存ordered_data_salary.txt文件
void write_data(int data[])
{
	ofstream outfile("ordered_data_salary.txt",ios::out);
	if(!outfile)
	{
		cerr<<"open ordered_data_salary.txt error!"<

你可能感兴趣的:(C++四大类排序算法)