quick——sort-- my
2013-04-20 11:41
351 查看
#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;
}
相关文章推荐
- my quick sort
- 3 way quick sort
- quick_sort.cc
- 快速排序(Quick_Sort)
- quick sort algorithm
- C program for quick sort
- NSMutaleArray Quick Sort
- 分治_递归_quick_sort
- Implementation of Quick Sort
- The Quick Sort
- 快速排序(Quick-Sort)
- 算法导论(implementation of quick sort)
- MergeSort and Quick Sort
- Quick sort C# code
- Algorithm: Quick Sort Mind and Related Questions
- Quick Sort & Binary Merge Sort
- 【代码积累】quick sort bia direction
- quick sort analyse
- 笔试算法题(54):快速排序实现之单向扫描、双向扫描(single-direction scanning, bidirectional scanning of Quick Sort)
- 快速排序的简单实现(Quick_Sort)