代码
//============================================================================
// Name : Sort.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
template<class T>
int partition(T data[],int low,int high)
{
int t=data[low];
while(low<high)
{
while(low<high&&t<=data[high])
high--;
if(low<high)
data[low++]=data[high];
while(low<high&&t>=data[low])
low++;
if(low<high)
data[high--]=data[low];
}
data[low]=t;
return low;
}
template<class T>
void quickSort(T data[],int i,int j)
{
int d;
if(i<j)
{
d=partition(data,i,j);
quickSort(data,i,d-1);
quickSort(data,d+1,j);
}
}
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
int t[]={12,34,6,-4,6,46,78,42,65,8,43};
quickSort(t,0,11);
for(int i=0;i<10;i++)
printf("%d ",t[i]);
return 0;
}
// Name : Sort.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
template<class T>
int partition(T data[],int low,int high)
{
int t=data[low];
while(low<high)
{
while(low<high&&t<=data[high])
high--;
if(low<high)
data[low++]=data[high];
while(low<high&&t>=data[low])
low++;
if(low<high)
data[high--]=data[low];
}
data[low]=t;
return low;
}
template<class T>
void quickSort(T data[],int i,int j)
{
int d;
if(i<j)
{
d=partition(data,i,j);
quickSort(data,i,d-1);
quickSort(data,d+1,j);
}
}
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
int t[]={12,34,6,-4,6,46,78,42,65,8,43};
quickSort(t,0,11);
for(int i=0;i<10;i++)
printf("%d ",t[i]);
return 0;
}