惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
I
InfoQ
IT之家
IT之家
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
博客园_首页
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler

博客园 - 无痕的泪

任务栏不显示任务、不能有文件拖动、粘贴操作 登陆qq.电脑重启 WEB测试之兼容性测试 如何编写测试计划 boot disk failure,insert system disk and press enter 使用数组的方法,解决Josephus问题 - 无痕的泪 - 博客园 网游名字-调查 赖子山庄工作记录 软件测试面试题目————征求更好答案 比google 百度 更强(http://www.new1000.cn ) google sitemap 介绍(转载) server 2003 directx被禁用 Sql server 2005 的安装 loadrunner的安装 LoadRunner8.1 安装汉化 出错 软件测试准备(摘要) 网站测试方法 软件测试(分类,方法,工具) 软件测试分类
quick sort 快速排序法
无痕的泪 · 2008-10-31 · via 博客园 - 无痕的泪

#include<iostream.h>

void qsort(int [],int,int);

void main()                    //quick sort 快速排序法
{
 int array[]={3,32,332,4,2,34,23,4,2,423};
 int len=sizeof(array)/sizeof(int);
 for(int i=0;i<len;i++)       //原始结果输出
  cout<<array[i]<<",";
 cout<<endl;

 qsort(array,0,len-1);

 for(int j=0;j<len;j++)         //排序结果输出
  cout<<array[j]<<",";
 cout<<endl;
}

void qsort(int a[],int left,int right)
{
 int pivot,l,r,temp;
 l=left;
 r=right;
 pivot=a[(left+right)/2];

 while(l<r)
 {
  while(a[l]<pivot) ++l;
  while(a[r]>pivot) --r;

  if(l>=r) break;

  temp=a[l];
  a[l]=a[r];
  a[r]=temp;

  if(l!=pivot) --r;
  if(r!=pivot) ++l;
 }
 if(l==r) l++;
 if(left<r) qsort(a,left,l-1);
 if(l<right) qsort(a,r+1,right);
}