My Carelessness

Back to your page!


Or leave your comments here.

RegendLa

导航

冒泡排序法

 

 

 

#include <stdio.h>
int swap(int *x,int *y)

{
	int temp;
	temp=*x;
	*x=*y;
	*y=temp;
}
int main()
{
	int a[501];
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int j=0;j<n-1;j++)
	{
		for(int i=j;(i>=0)&&(a[i]>a[i+1]);i--)
		{
			swap(&a[i],&a[i+1]);
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("%d ",a[i]);
	}
	return 0;
}

 

posted on 2014-12-30 18:02  最爱七  阅读(214)  评论(0编辑  收藏  举报




Thanks for your coming!
If what you read helps,I would appreciate!