quick——sort-- my
来源:互联网 发布:申请淘宝企业店铺条件 编辑:程序博客网 时间:2024/06/03 21:49
#include <iostream>
using namespace std;
//quick sort
/*
Qsort(int a[],int l, int r)
{
// destribute it
//if(l<r)//递归调用的返回条件
{
int pit = (a,l,r)
Qsort(a,l,pit-1);
Qsort(a,pit+1,r);
}
}ggt
*/
void my_swap(int &a, int &b)
{// 1 ^ 0 = 1; 相同为0 ; 相异 取 或;0 ^ 1 = 0;
/*a = a^b;
b = a^b;
a = a^b;*/
int temp = b;
b=a;
a=temp;
}
void my_swa22p(int &a, int &b)
{
a = a^b;
b = a^b;
a = a^b;
}
int partit(int a[],int l,int r)
{
// r is the same of length
//1 = get the pivot element
//2 = divide
int pivot = a[r];
int j = l;
int i = j-1;
for(int j = l;j<=r-1;++j)
{
if(a[j]<pivot)
{
i++;// point to one which is the first big than pivot
my_swap(a[i],a[j]);
}
if(a[j]>=pivot)
{
continue;
}
}
my_swap(a[i+1],a[r]);//这里要进行修改 ··!!!!!
return i+1;
}
void QuickSort(int a[],int l,int r)
{
if(l<r)
{
int pit = partit(a,l,r);//put the pivot element in the right pit position
QuickSort(a,l,pit-1);
QuickSort(a,pit+1,r);//**
}
}
int main ()
{
int arr1 []={-1,3,4,1,3};
QuickSort(arr1,1,4);
int size=sizeof(arr1)/sizeof(arr1[0]);
for(int i=1;i<size;++i)
cout<<arr1[i]<<' ';
int a = 3;int b = 3;
//cout <<"a = "<<a << "b= "<<b<<endl;
//my_swa22p(a,a);
//cout <<"_a = "<<a << "_b= "<<a<<endl;
system("pause");
return 0;
}
using namespace std;
//quick sort
/*
Qsort(int a[],int l, int r)
{
// destribute it
//if(l<r)//递归调用的返回条件
{
int pit = (a,l,r)
Qsort(a,l,pit-1);
Qsort(a,pit+1,r);
}
}ggt
*/
void my_swap(int &a, int &b)
{// 1 ^ 0 = 1; 相同为0 ; 相异 取 或;0 ^ 1 = 0;
/*a = a^b;
b = a^b;
a = a^b;*/
int temp = b;
b=a;
a=temp;
}
void my_swa22p(int &a, int &b)
{
a = a^b;
b = a^b;
a = a^b;
}
int partit(int a[],int l,int r)
{
// r is the same of length
//1 = get the pivot element
//2 = divide
int pivot = a[r];
int j = l;
int i = j-1;
for(int j = l;j<=r-1;++j)
{
if(a[j]<pivot)
{
i++;// point to one which is the first big than pivot
my_swap(a[i],a[j]);
}
if(a[j]>=pivot)
{
continue;
}
}
my_swap(a[i+1],a[r]);//这里要进行修改 ··!!!!!
return i+1;
}
void QuickSort(int a[],int l,int r)
{
if(l<r)
{
int pit = partit(a,l,r);//put the pivot element in the right pit position
QuickSort(a,l,pit-1);
QuickSort(a,pit+1,r);//**
}
}
int main ()
{
int arr1 []={-1,3,4,1,3};
QuickSort(arr1,1,4);
int size=sizeof(arr1)/sizeof(arr1[0]);
for(int i=1;i<size;++i)
cout<<arr1[i]<<' ';
int a = 3;int b = 3;
//cout <<"a = "<<a << "b= "<<b<<endl;
//my_swa22p(a,a);
//cout <<"_a = "<<a << "_b= "<<a<<endl;
system("pause");
return 0;
}
- quick——sort-- my
- my quick sort
- 模板——Quick Sort
- 模板——Quick Sort
- 泛型算法——quick sort
- 算法与数据结构——快速排序 Quick Sort
- 快速排序(quick sort)——数据结构与算法复习
- 数据结构与算法学习笔记——quick sort
- 算法导论——快速排序(Quick-Sort)
- 排序算法——快速排序(Quick Sort)
- 排序——快速排序(quick sort)
- 算法分析之——quick-sort快速排序
- 排序算法——快速排序(Quick Sort)
- 交换排序—快速排序(Quick Sort)
- 交换排序—快速排序(Quick Sort)
- 交换排序—快速排序(Quick Sort)
- 交换排序—快速排序(Quick Sort)
- Quick Sort
- Even Parity(偶数矩阵)
- crs_stat 各资源名称对应
- linux进程间通信--socket套接字 实例代码
- 小试mini210sGPIO驱动Led灯
- Java设计模式之十五(桥接模式)
- quick——sort-- my
- 说说 iphone 数据线(充电线) 原装正品和仿制品、假货等的区别
- 内核对象
- java.lang.NoClassDefFoundError: org/jaxen/JaxenException
- 区分Activity的四种加载模式
- 职场必知的20条黄金法则
- DirectX SDK版本与Visual Studio版本
- android:屏幕自适应
- 选项卡【javascript/jquery】