#include <iostream>
#include <stddef.h>
using namespace std;
/***************获取数组长度***************/
template <class T>
int length(T& array)
{
return (sizeof(array)/sizeof(array[0]));
}
/************插入排序*******************/
template<class T>
void insertsort(T a[],int n)
{
int i,j;
T temp;
for(i=1;i<n;i++)
{
j=i;
temp=a[j];
while(j>0&&a[j-1]>temp)
{
a[j]=a[j-1];
j--;
}
a[j]=temp;
}
}
/***********************选择排序**********************/
template<class T>
void selectsort(T a[],int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
/*****************快速排序**********************/
template<class T>
void quicksort(T a[], int first, int end)
{
int i=first,j=end,temp=a[first];
while(i<j)
{
while(a[j]>=temp)
j--;
a[i]=a[j];
while(a[i]<=temp)
i++;
a[j]=a[i];
}
a[i]=temp;
if(first<i-1)
quicksort(a,first,i-1);
if(end>i+1)
quicksort(a,i+1,end);
}
/*******************显示排好的数组*******************/
template<class T>
void display(T a,int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<a[i]<<' ';
}
}
void main()
{
int a[]={7,8,9,3,7,8};
quicksort(a,0,5);
display(a,6);
}