swap函数

来源:互联网 发布:淘宝退货预约快递上门 编辑:程序博客网 时间:2024/05/16 16:19
void myswap(int *a,int *b){
 int temp;
 temp=*a;
 *a=*b;
 *b=temp;
}
void myswap(int &a,int &b){
 int temp;
 temp=a;
 a=b;
 b=temp;
}
void myswap1(int a,int b)
{
 int temp;
 temp=a;
 a=b;
 b=temp;
}
void main(){
 int a=3,b=4;
 cout<<a<<b<<endl;
 myswap(&a,&b);
 cout<<a<<b<<endl;
 myswap(a,b);
 cout<<a<<b<<endl;
 myswap1(a,b);
 cout<<a<<b<<endl;
}
原创粉丝点击