Chinaunix首页 | 论坛 | 博客
  • 博客访问: 545238
  • 博文数量: 252
  • 博客积分: 1068
  • 博客等级: 少尉
  • 技术积分: 1775
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-05 21:33
文章分类

全部博文(252)

文章存档

2013年(21)

2012年(231)

分类:

2012-06-04 14:36:28

原文地址:快速排序 作者:kevin33643

#include
using namespace std;
 
void QuickSort(int R[],int low,int high)
{
    int temp;//枢轴元素
    if(low    {
        temp=R[low];//以数组的第一个元素作为基准进行划分
        int i=low,j=high;
        while(i        {
            while(i            if(i            while(iR[i])i++;//从左向右扫描,找到第一个值大于temp的R[i]
            if(i        }
        R[i]=temp;//枢轴元素移到合适的位置
        QuickSort(R,low,i-1);
        QuickSort(R,i+1,high);
  }
}
int main()
{
    int i=0;
    int R[10]={3,7,6,1,5,9,8,4,2,0};
    QuickSort(R,0,9);
    while(i<10)
    {
        cout<        i++;
    }
    return 0;
}
阅读(550) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~