您的位置:首页 > 其它

简单的指针三个数排序

2009-11-12 13:06 197 查看
Code:

#include<iostream>   

using namespace std;   

int main()   

{ void exchange(int *,int *,int *);   

int a,b,c,*p1,*p2,*p3;   

cin>>a>>b>>c;   

p1=&a;p2=&b;p3=&c;   

exchange(p1,p2,p3);   

cout<<a<<"  "<<b<<"  "<<c<<endl;   

}   

void exchange ( int *q1,int *q2,int *q3)   

{ void swap(int *,int *);   

if(*q1<*q2) swap(q1,q2);   

if(*q1<*q3) swap(q1,q3);   

if(*q2<*q3) swap(q2,q3);   

}   

void swap (int *pt1,int *pt2)   

{int temp;   

temp=*pt1;   

*pt1=*pt2;   

*pt2=temp;   

}   

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  exchange c