排序综合程序设计(快速,希尔,插入,选择,冒泡)

#include"iostream"
#include"cstdio"
#include"stdlib.h"
#include"cstring"
#include"cstdlib"
#include"vector"
#include"map"
#include"algorithm"
#include <iomanip>
#include <time.h>
#include <fstream>
#include <sstream>
using namespace std;
typedef pair<string, double> PAIR;
struct CmpByValue
{
   
    bool operator()(const PAIR& lhs, const PAIR& rhs)
    {
   
        return lhs.second < rhs.second;
    }
};
//上述代码用于让map按value进行排序
const int M = 40000 ;//数据
map<string,double>Map;//用于排序算法的快慢
int mp[M];      //用于装随机数的数组;

void Random_number()//生成随机数的函数
{
   
    int RandomNumber;
    srand((unsigned)time(NULL));//time()用系统时间初始化种。为rand()生成不同的随机种子。
    for(int i=0; i<M; i++)
    {
   
        RandomNumber = rand();//每次生成一个随机数
        mp[i]=RandomNumber;//赋值给数组
    }
}
void quicksort(int left, int right, vector<int>& num) // 快速排序,从小到大,递归
{
   
    if(left >= right)
        return;
    int i, j, base;
    i = left, j = right;
    base = num[left];  //取最左边的数为基准数
    while (i < j)
    {
   
        while (num[j] >= base && i < j)
            j--;
        while (num[i] <= base && i < j)
            i++;
        if(i < j)
        {
   
           swap(num[i],num[j]);
        }
    }
    //基准数归位
    num[left] = num[i];
    num[i] = base;
    quicksort(left, i - 1, num);//递归左边
    quicksort(i + 1, right
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值