bucketsort.cpp

来自「各种内部排序算法的集合」· C++ 代码 · 共 34 行

CPP
34
字号
//桶式排序

#include "iostream.h"
#include "stdlib.h"
#include "string.h"
#include "Compare.h"
#include "BucketSorter.h"

// 设定随即函数的种子
inline void Randomize() 
  { srand(1); }

//返回一个0到n-1之间的随机数
inline int Random(int n)
  { return rand() % (n); }

void main()
{
	//产生随机数组,长度为100
	Randomize();	
	int * sortarray =new int[100];
	for(int i=0;i<100;i++)
		sortarray[i]=Random(100);
	//实例化桶式排序类
	BucketSorter<int> sorter;
	//输出排序前数组内容
	cout<<"排序前:";cout<<endl;
	sorter.PrintArray(sortarray,100);
	//排序
	sorter.Sort(sortarray,100,100);
	//输出排序后数组内容
	cout<<"排序后:";cout<<endl;
	sorter.PrintArray(sortarray,100);
}

⌨️ 快捷键说明

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