//
// Created by 刘彪 on 2020/3/1.
//快速排序(模版) p177
#include <iostream>
#include <cstdio>
using namespace std;
template <class T>
void mysort(T a[],int n){
int i,j;
T temp;
for(i=1;i<n;i++){
j = i;
temp = a[i];
while(j>0 && temp < a[j-1]){
a[j] = a[j-1];
j--;
}
a[j] = temp;
}
}
template <class T>
void disp(T a[],int n){
for(int i=0;i<n;i++) cout<<a[i]<<" ";
cout<<endl;
}
int main(){
int a[] = {3,8,2,6,7,1,4,9,5,0};
char b[] = {'i','d','a','j','b','f','e','c','g','h'};
cout<<"整数排序:"<<endl;
cout<<" 原序列:"<<endl;
disp(a,10);
mysort(a,10);
cout<<" 新序列:";
disp(a,10);
cout<<"字符排序"<<endl;
cout<<" 原序列:";
disp(b,10);
mysort(b,10);
cout<<" 新序列:";
disp(b,10);
}