十万(10万)级别数据的冒泡排序(冒泡排序算法排序十万(10万)级别的数据)

来源:互联网 发布:淘宝运营工资是多少 编辑:程序博客网 时间:2024/06/01 08:44
引入指针排序的效率高于普通的效率,指针排序的效率是普通排序的4倍(以10万条数据为例)

一,普通排序

class my_maopao{public:    void my_mppx();    void zz_my_mppx();    ~my_maopao();private:    int temp;    time_t ts;    unsigned int num;    int data;//随机数};


void my_maopao::my_mppx(){    int buf[length] = {0};    num = time(&ts);    srand(num);//随机数    int i = 0;    while (i<length)    {        data = rand() % 100;        buf[i] = data;        /*cout << data<<"  ";        if (i%20==0)        {            cout << endl;        }        Sleep(100);*/        i++;    }    cout << "数组初始化成功......" <<system("pause")<<endl;    for (int i = 0;i < length;i++)    {        for (int j = 0; j < length -1; j++)        {            if (buf[j + 1] < buf[j])            {                temp = buf[j + 1];                buf[j + 1] = buf[j];                buf[j] = temp;            }        }    }    cout << "排序ok....." << endl;    /*for (int i = 0; i < length; i++)    {        cout << buf[i]<<"   ";        if (i%10==0)        {            cout << endl;        }    }*/}



二,引入指针的排序

class my_maopao{public:    void zz_my_mppx();    ~my_maopao();private:    int temp;    time_t ts;    unsigned int num;    int data;//随机数};



void my_maopao::zz_my_mppx(){    int buf[length] = { 0 };    int *zz=buf,*zz1=buf+length,temp;    num = time(&ts);    srand(num);//随机数    int i = 0;    while (i<length)    {        data = rand() % 100;        buf[i] = data;        //cout << data << "  ";        i++;        /*if (i % 10 == 0)        {            cout << endl;        }*/    }    cout << "数组初始化成功......" << endl << endl<<endl;    for (zz = buf; zz < buf+length; zz++)    {        for (zz1=zz+1; zz1 < buf+length; zz1++)        {            if (*zz1>*zz)            {                temp = *zz;                 *zz = *zz1;                *zz1 = temp;            }        }    }    cout << "排序ok....." << endl;    /*for (zz=buf; zz < (buf + length); zz++)    {        cout << *zz<<"   ";        if (i % 10 == 0)        {            cout << endl;        }        i++;    }*/}


0 0
原创粉丝点击