快速排序

#include<iostream>
using namespace std;
/*
  Name: 
  Copyright: 
  Author: 
  Date: 08/06/13 10:30
  Description:  
*/

template<typename T>
int  partion(T t[],int p,int r)
{
     T x=t[r];
     T temp;
     int i=p-1;
     int j;
     for(j=p;j<r;j++)
     {        
         if(t[j]<=x)    
         {
             temp=t[j];
             t[j]=t[++i];
             t[i]=temp;
         }    
     }
     t[r]=t[++i];
     t[i]=x;
     return i;
}

template<class T>
void QuickSort(T t[],int s,int f)
{
     int m;
     if(s<f)
     {
        m=partion<T>(t,s,f);
        QuickSort(t,s,m-1);
        QuickSort(t,m+1,f);
     }
}

int main()
{
    
    return 0;
    } 


posted @ 2013-06-08 20:39  爱生活,爱编程  阅读(200)  评论(0)    收藏  举报