快速排序算法C++实现
来源:互联网 发布:波士顿矩阵图怎么画 编辑:程序博客网 时间:2024/06/15 17:52
#include <iostream>
using namespace std;
void display( int arr[],int num)
{
int i = 0;
for( i = 0;i<num;i++)
{
cout << arr[i] << "#";
}
cout << endl;
}
int Partition( int array[],int low,int high )
{
int i,j = 0;
int key = array[low];
while(low< high)
{
while( ( low < high ) && ( array[high] > key ) )
{
high--;
}
array[low] = array[high];
while(( low < high ) && ( array[low] <= key ) )
{
low ++;
}
array[high] = array[low];
}
array[low] = key;
return low;
}
static void QuickSort( int array[],int low,int high )
{
int location = 0;
if( low < high )
{
location = Partition( array,low,high);
QuickSort( array,low,location - 1 );
QuickSort( array,location + 1,high );
}
}
int main()
{
int arr[100] = {0};
int count = 0;
cout << "please input the number of int :" << endl;
cin >> count;
cout << "your input is:" << endl;
for(int i = 0;i < count;i++)
{
cin >> arr[i];
}
cout << "after quicksort is:" << endl;
QuickSort(arr,0,count-1);
display(arr,count);
return 0;
}
using namespace std;
void display( int arr[],int num)
{
int i = 0;
for( i = 0;i<num;i++)
{
cout << arr[i] << "#";
}
cout << endl;
}
int Partition( int array[],int low,int high )
{
int i,j = 0;
int key = array[low];
while(low< high)
{
while( ( low < high ) && ( array[high] > key ) )
{
high--;
}
array[low] = array[high];
while(( low < high ) && ( array[low] <= key ) )
{
low ++;
}
array[high] = array[low];
}
array[low] = key;
return low;
}
static void QuickSort( int array[],int low,int high )
{
int location = 0;
if( low < high )
{
location = Partition( array,low,high);
QuickSort( array,low,location - 1 );
QuickSort( array,location + 1,high );
}
}
int main()
{
int arr[100] = {0};
int count = 0;
cout << "please input the number of int :" << endl;
cin >> count;
cout << "your input is:" << endl;
for(int i = 0;i < count;i++)
{
cin >> arr[i];
}
cout << "after quicksort is:" << endl;
QuickSort(arr,0,count-1);
display(arr,count);
return 0;
}
阅读全文
0 0
- 快速排序算法(c#)实现
- 排序算法(C实现)--------- 快速排序
- QUicKSort 快速排序算法 c实现
- 快速排序C语言算法实现
- c语言实现快速排序算法
- 快速排序算法实现(C++)
- 纯c实现快速排序算法
- 快速排序算法(C & Java 实现)
- 快速排序算法的c语言实现
- 快速排序算法实现(C版)
- 快速排序算法的C/C++ 实现
- 快速排序算法的C语言实现
- 算法导论C语言实现: 快速排序
- 快速排序算法 C语言实现
- 直白快速排序算法,C语言实现
- C语言快速排序算法实现
- 【算法】C语言实现的快速排序
- C语言实现数组快速排序算法
- Redis入门指南之数据类型
- httpcomponents-client-4.5.3 学习笔记(2) 1.2 HttpClient接口
- xpath抓取代理IP并检测IP的有效性
- jsonp详解
- jQuery实现表格冻结行和列
- 快速排序算法C++实现
- android 简单实现,微信第三方登录
- 图解集合 4 :HashMap
- 转载:在VC下获取原始MAC地址
- PAT 1042. Shuffling Machine (20)
- 为mysql数据库建立索引
- Android JNI之青春期 Cmake(android studio)
- Java编码规范——google
- Qt智能指针学习总结