您当前的位置: 首页 > 

精简易懂的快速排序,插入排序,大顶堆排序

发布时间:2018-11-28 21:55:07 ,浏览量:6

#include
using namespace std;
 
//快速排序,在子函数中,数组已被改变
void quick_sort(int *a, int left, int right) //left和right为索引值
{
    int temp; //存储每次选定的基准数(从最左侧选基准数)
    int t;
    int initial=left;
    int end=right;
    temp=a[left];
 
    //***必须有这一部分***//
    if (left>right)  //因为在递归过程中有减1加1的情况,当其越界时,直接return,不返回任何值,即结束当前程序块
        return;   
 
    while(left!=right)  //此时左右index在移动中,若left==right,则跳出循环,将基数归位
    {
        while(a[right]>=temp && left

关注
打赏
查看更多评论

暂无认证

  • 6浏览

    0关注

    115983博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录