/*****************************************************
*
* Main: 冒泡排序
* Code by: Xiangjie.Huang
* Date: 2014/08/18
* Blog: http://blog.163.com/surgy_han
*
* <----------------Details: start------------>
*
* (1) 比较相邻的元素, 如果第一个比第二个大,
* 就交换他们两个
*
* <----------------Details: end-------------->
*
*****************************************************/
//#pragma comment(linker, "/STACK:61400000,61400000")
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define pi 3.1415926535897932385
#define LL64 __int64
#define LL long long
#define oo 2147483647
#define N 1010
#define M 210
#define INF 1e9
int data[N];
void InputData(int n)
{
for (int i = 0; i < n; i++)
{
scanf("%d", &data[i]);
}
}
void Output(int n)
{
for (int i = 0; i < n; i++)
{
printf("%d ", data[i]);
}
printf("\n");
}
void Sort_of_Bubble(int n)
{
InputData(n);
bool p = 1;
while (p)
{
p = 0;
for (int i = 0; i < n - 1; i++)
{
if (data[i] > data[i + 1])
{
p = 1;
data[i] ^= data[i + 1];
data[i + 1] ^= data[i];
data[i] ^= data[i + 1];
}
}
}
Output(n);
}
int main()
{
int n;
//freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
while (~scanf("%d", &n))
{
Sort_of_Bubble(n);
}
return 0;
}
冒泡排序
最新推荐文章于 2022-04-29 23:24:15 发布