- #include <iostream>
- using namespace std;
- void BubbleSort(int *a,int size)
- {
- int temple;
- for(int i=1;i<10;i++)//需要排列的次数
- {
- for(int j=0;j<10-i;j++)//每次排列的次序
- {
- if(a[j]>a[j+1])
- {
- temple=a[j];
- a[j]=a[j+1];
- a[j+1]=temple;
- }
- }
- /* for(int k=0;k<10;k++)
- {
- cout<<a[k]<<" ";
- }
- cout<<endl;*/
- }
- }
- void main()
- {
- int a[10]={55,2,6,4,32,12,9,72,26,37};
- BubbleSort(a,10);
- for(int n=0;n<10;n++)
- cout<<a[n]<<" ";
- }
c++冒泡实现
最新推荐文章于 2024-01-22 11:38:30 发布