快速排序 C++
来源:互联网 发布:软件服务外包合同范本 编辑:程序博客网 时间:2024/05/21 09:55
讲解建议大家直接看算法导论
#include <iostream>using namespace std;int Partition(int a[],int,int);void QuickSort(int a[],int,int);int main(){ int a[10] = {1,2,4,56,25,1,33,6,77,1}; int len = sizeof(a)/sizeof(int); cout<<"origin:"<<endl; for(int i=0;i<len;i++) { cout<<a[i]<<" "; } cout<<endl<<"sorted:"<<endl; QuickSort(a,0,len-1); for(int i=0;i<len;i++) { cout<<a[i]<<" "; } cout<<endl; return 0;}int Partition(int a[],int p,int r){ int x = a[r]; int i = p-1; for(int j=p;j<=r-1;j++) { if(a[j]<=x) { i=i+1; int temp =a[j]; a[j]=a[i]; a[i] = temp; } } int temp = a[r]; a[r] = a[i+1]; a[i+1] = temp; return i+1;}void QuickSort(int a[],int p,int r){ if(p<r) { int q = Partition(a,p,r); QuickSort(a,p,q-1); QuickSort(a,q+1,r); }}
1 0
- 排序-快速排序(c)
- 快速排序--C语言
- 快速排序(c#)
- 快速排序C
- C++快速排序算法
- 快速排序QuickSort.c
- 快速排序(C#)
- 快速排序算法 C
- 快速排序(C++)
- 快速排序C语言
- (C#)快速排序 Quicksort
- 快速排序 C代码
- 快速排序(C)
- C快速排序算法
- 快速排序 Java/C
- C快速排序
- 快速排序C语言版
- 快速排序--C语言
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains(树状数组)
- 多关键字排序-oj考试排名10.1.3
- C#使用委托实现主窗体向子窗体发送消息
- 优先级队列
- POJ 1124 Oh, Those Achin' Feet 笔记
- 快速排序 C++
- 多边形划分
- html创建无序列表
- bzoj 3527 [Zjoi2014]力
- swoole搭建简易聊天室
- XML-1
- 有关PHP表单中 input type类型的介绍
- html符号不一的无序列表
- 《MySQL必知必会》笔记(前13章)