快速排序
来源:互联网 发布:万能网络摄像头软件 编辑:程序博客网 时间:2024/06/05 08:47
// QuickSort.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>#include<stdio.h>using namespace std;int Partition(int *A, int low, int high) {int pivot = A[low];while (low<high) {while ((low < high)&&(A[high] >= pivot)) --high;A[low] = A[high];while ((low < high)&&(A[low] <= pivot)) ++low;A[high] = A[low];}//end whileA[low] = pivot;return low;}void QuickSort(int *A, int low, int high) {if (low<high) {int pivotpos = Partition(A, low, high);QuickSort(A, low, pivotpos - 1);QuickSort(A, pivotpos + 1, high);}//end if}int main() {int A[] = { 24,38,29,20,5,31,27 };QuickSort(A, 0, 6);for (int i = 0; i < 7; i++) {cout << A[i] << endl;}return 0;}
阅读全文
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 2017.8.8测试 题四 迷之阶梯
- 基本类型和引用类型的变量在内存存放的内容及对象
- 【C语言】格式控制符
- 9-顺序容器
- 第一个爬虫实例-简单抓取网页内容
- 快速排序
- 学习笔记(六)模块、包、正则表达式
- 标准C语言头文件 ISO C标准定义的头文件(24项)
- 产品经理分析模型
- Linux 的启动流程
- 【BBED】BBED模拟并修复ORA-08102错误
- ReshapeTheMatrix
- 关于table边框,设置了border-collapse:collapse之后,各条边框是怎么合并的?
- [BZOJ1596][Usaco2008 Jan]电话网络(树形dp)