///////////////////////////////////////////////////////////////////
//Author: 张弦,SA10225244
//Time: 2010-12
//
//
//Task: 实现合并排序,插入排序,希尔排序,
// 快速排序,冒泡排序,桶排序算法
//
///////////////////////////////////////////////////////////////////
#include <iostream>
#include <time.h>
#include <iomanip>
using namespace std;
#include "insort_sort.h"
#include "merge_sort.h"
#include "bubble_sort.h"
#include "quick_sort.h"
#include "heap_sort.h"
#include "bucket_sort.h"
#include "shell_sort.h"
//
//随机数获取函数
double* rand_get(int count)
{
srand(time(NULL));
double *rand_buf = new double[count];
for(int i=0; i<count; i++)
{
rand_buf[i] = rand()/((double)RAND_MAX);
}
return rand_buf;
}
int main()
{
//设置输出数的宽度
cout.setf(ios::fixed);
cout.precision(10);
cout<<"输入样本空间大小:"<<endl;
int count=0; //数组大小
cin >> count;
double *buf1 = rand_get(count);
double *buf2 = rand_get(count);
double *buf3 = rand_get(count);
double *buf4 = rand_get(count);
double *buf5 = rand_get(count);
double *buf6 = rand_get(count);
// for(int i=0; i<count; i++)
// cout << buf[i] << " ";
// cout<<endl;
insert_sort(buf1,count);
bubble_sort(buf2,count);
merge_sort(buf3,count);
quick_sort(buf4,count);
// heap_sort(buf,count);
shell_sort(buf5,count);
bucket_sort(buf6,count,10000);
delete[] buf1,buf2,buf3,buf4,buf5,buf6;
return 0;
}
评论0