#include <iostream>
#include <vector>
using namespace std;
template<typename Type>
void quicksort(vector<Type>& v,int left,int right)
{
if(left!=right)
{int q=partition(v,left,right);//q是标准元素所在的位置的序号
quicksort(v,left,q-1);
quicksort(v,q+1,right);
} //我在这里时观察了left和right的值,当left=right的时候还是不能挑出quicksort的循环 !!
//各位大侠帮忙看看
}
template<typename Type>
int partition(vector<Type>& v,int left,int right)
{int v_std=v.at(left);
vector<Type>temp1;
vector<Type>temp2;
int i=left,j=0;
for(;i<=right;i++)
{if(v_std<v.at(i))
{temp1.push_back(v.at(i));
}
if(v_std>v.at(i))
{temp2.push_back(v.at(i));
j++; }
}
i=left;
for(int k=0;k<temp2.size();k++){
v.at(i)=temp2.at(k);i++;}
v.at(i)=v_std;
i++;
for(int k=0;k<temp1.size();k++){
v.at(i)=temp1.at(k);i++;}
return j;
}
int main(int argc, char *argv[])
{ int a[]={10,7,6,4,3,1,};//17,99,23,12,8,11};
int a_size=sizeof(a)/sizeof(a[0]);
vector<int> v(a,a+a_size);
int right=a_size-1;
quicksort(v,0,right);//a_size就是a 所含元素的个数
system("PAUSE");
return EXIT_SUCCESS;