Copyright (c)2012, 烟台大学计算机学院
* All rightsreserved.
* 文件名称:zifuchuan.cpp
* 作 者: 杨蕾
* 完成日期:2012年12月20 日
* 版 本 号: v1.0
* 输入描述:无
* 问题描述: 略
* 程序输出: 略
* 问题分析: 略
#include <iostream>
using namespace std;
void sort(int &,int &,int &);
int main()
{
int a,b,c;
cout<<"请输入三个整数:";
cin>>a>>b>>c;
sort(a,b,c);
cout<<"排序后的顺序是:"<<a<<" "<<b<<" "<<c<<endl;
return 0;
}
void sort(int &e,int &f,int &j)
{
void s(int &,int &);
if(e<f)
s(e,f);
if(e<j)
s(e,j);
if(f<j)
s(f,j);
}
void s(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
}
运行结果:
心得体会:
在c++的编程中要慎用swap,否则可能导致该程序不能正常运行。