#include <iostream>
#include <string>
using namespace std;
template <class T>
void sort(T *a, int size)
{
int r, i, j;
for(i = 0; i < size; i++)
cin >> a[i];
T t;
for(r = size / 2; r >= 1; r /= 2)
for(i = r; i < size; i++)
{
t = a[i];
j = i - r;
while(j >= 0 && t < a[j])
{
a[j + r] = a[j];
j -= r;
}
a[j + r] = t;
}
}
template <class T>
void display(T* a, int size){
for(int i=0; i<size-1; i++) cout<<a[i]<<' ';
cout<<a[size-1]<<endl;
}
int main() {
const int SIZE=10;
int a[SIZE];
char b[SIZE];
double c[SIZE];
string d[SIZE];
int ty, size;
cin>>ty;
while(ty>0){
cin>>size;
switch(ty){
case 1:sort(a,size); display(a,size); break;
case 2:sort(b,size); display(b,size); break;
case 3:sort(c,size); display(c,size); break;
case 4:sort(d,size); display(d,size); break;
}
cin>>ty;
}
return 0;
}
标签:sort,ty,int,pta,SIZE,排序,display,模板,size From: https://www.cnblogs.com/atrue/p/17413098.html