語法:
#include <iostream>
#include <cstdlib>
using namespace std;
void swap(int,int,int);
int main(void)
{
int a=3,b=5,c=2;
cout << "Before swap...";
cout << "a=" << a << ",b=" << b << ",c=" << c <<endl;
cout << "After swap...";
swap(a,b,c);
cout << "a=" << a << ",b=" << b <<",c=" << c << endl;
system("pause");
return 0;
}
void swap(int x,int y,int z)
{
int temp;
if (x>y){
x=x;
y=y;
}else
{
temp=x;
x=y;
y=temp;
}
if (x>z){
x=x;
z=z;
}else
{
temp=x;
x=z;
z=temp;
}
if (y>z){
y=y;
z=z;}else
{
temp=y;
y=z;
z=temp;
}
return;
}
我這樣寫結果竟然沒有作氣泡排列