您的位置:首页 > 其它

冒泡排序(算法源码)

2014-05-19 02:01 162 查看
算法源码:

//BubbleSort.cpp

#include <iostream>
using namespace std;

void BubbleSort(int a[], int n)
{
for(int i=n-1;i>0;i--)
{
for(int j=0;j<i;j++)
{
if (a[j]>a[j+1])
{
int tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
}
int main()
{
int a[]={4,3,6,9,7,5,1,10,2,15,8,7,6};
BubbleSort(a,sizeof(a)/sizeof(a[0]));
cout<<"after bubble sort."<<endl;
for (int i=0;i<sizeof(a)/sizeof(a[0]);i++)
{
cout<<a[i]<<" ";

}
cout<<endl;
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: