/*
* Copyright (c) 2016,烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:main.cpp
* 作 者:王俊锐
* 完成日期:2016年6月16日
* 版 本 号:v1.0
*
* 问题描述:是一个函数模板的两个实例,其功能是将数组a中的前size个元素按从小到大顺序排列。试设计这个函数模板
*/
#include <iostream>
using namespace std;
void Sort(int a[],int size);
void Sort(double a[],int size);
int main()
{
int a[10]={9,5,7,3,1,4,8,6,10,2};
Sort(a,5);
for(int i=0;i<10;i++)
cout<<a[i]<<" ";
cout<<endl;
double b[10]={9,5,7,3,1,4,8,6,10,2};
Sort(b,8);
for(int i=0;i<10;i++)
cout<<b[i]<<" ";
return 0;
}
void Sort(int a[],int size)
{
for(int i=0;i<size;++i)
for(int j=i+1;j<size;++j)
{
int temp;
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
void Sort(double a[],int size)
{
for(int i=0;i<size;++i)
for(int j=i+1;j<size;++j)
{
double temp;
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}