• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
小小松
学习技术不只是为养家糊口,也为夜深人静的时候能够一个人静静享受这其中的乐趣。
博客园    首页    新随笔       管理     
排序 快速排序
int Partion(int asy[],int begin,int end)
{
    int k=begin;

    int key=asy[end];

    for(int i=begin;i<=end;++i)
    {
        if(asy[i]>key)
        {
            int temp=asy[k];
            asy[k]=asy[i];
            asy[i]=temp;
            k++;
        }
    }
    int temp=asy[k];
    asy[k]=asy[end];
    asy[end]=temp;
    return k;
}

void QuickSort(int asy[],int begin,int end)
{
    if(begin<end)
    {
        int k=Partion(asy,begin,end);
        QuickSort(asy,begin,k-1);
        QuickSort(asy,k+1,end);
    }
}

    int asy[]={1,3,5,78,0,4,8,2,46,8,9,23};
    int size=sizeof(asy)/sizeof(int);
    QuickSort(asy,0,size-1);
    for(int i=0;i<size;++i)
    {
        std::cout<<asy[i]<<" ";
    }
    std::cout<<endl;

 

 

 

学习技术不只是为养家糊口,也为夜深人静的时候能够一个人静静享受这其中的乐趣。
posted on 2013-06-26 22:30  小小松  阅读(255)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3