冒泡排序简易代码

include

using namespace std;
void tmp(int *number1,int *number);
int main()
{
int number[10];
int n;
cout << “Please enter n” << endl;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> number[i];
}
for (int m = n; m>0; m–)
{
for (int j = 0; j < m-1; j++)
{
int o;
o = j;
if (number[o] > number[j + 1])
tmp(&number[o],&number[j+1]);
}
}
for (int e = 0; e < n; e++)
{
cout << number[e];
}
cout << endl;
return 0;
}
void tmp(int *number1, int *number)
{
int temp;
temp = * number1;
*number1 = *number;
*number = temp;

}

你可能感兴趣的:(c语言)