swap交换函数,用指针实现.#include "stdafx.h"void swap(int &a,int &b ){int* p=&a;int* q=&b; int* t ;if(*p>*q){ t=p;p=q;q=t;}//a=*p;//b=*q;}int main(){int a=12;int b= 1;printf("a=%d\n b = %d \n",a,b);swap(a,b);printf("a=%d \n b = %d \n",a,b);re
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 16:07:23
swap交换函数,用指针实现.#include "stdafx.h"void swap(int &a,int &b ){int* p=&a;int* q=&b; int* t ;if(*p>*q){ t=p;p=q;q=t;}//a=*p;//b=*q;}int main(){int a=12;int b= 1;printf("a=%d\n b = %d \n",a,b);swap(a,b);printf("a=%d \n b = %d \n",a,b);re
swap交换函数,用指针实现.
#include "stdafx.h"
void swap(int &a,int &b )
{
int* p=&a;
int* q=&b;
int* t ;
if(*p>*q)
{
t=p;
p=q;
q=t;
}
//a=*p;
//b=*q;
}
int main()
{
int a=12;
int b= 1;
printf("a=%d\n b = %d \n",a,b);
swap(a,b);
printf("a=%d \n b = %d \n",a,b);
return 0;
}
swap交换函数,用指针实现.#include "stdafx.h"void swap(int &a,int &b ){int* p=&a;int* q=&b; int* t ;if(*p>*q){ t=p;p=q;q=t;}//a=*p;//b=*q;}int main(){int a=12;int b= 1;printf("a=%d\n b = %d \n",a,b);swap(a,b);printf("a=%d \n b = %d \n",a,b);re
void swap(int a,int b )
{
int* p=&a;
int* q=&b;
int temp;
if(a>b)
{
temp=*p;
*p=*q;
*q=temp;
}
}
int main()
{
int a=12;
int b= 1;
swap(a,b);
cout