#include<iostream>
using namespace std;
void BubbleSort(int a[], int n)
{
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (a[j]>a[j + 1])
{
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}
int main()
{
int array[] = { 34, 65, 12, 43, 67, 5, 78, 10, 3, 70 };
int len = sizeof(array) / sizeof(int);
cout << "the original array are:" << endl;
for (int k = 0; k < len; k++)
cout << array[k] << " ";
cout << endl;
BubbleSort(array, len);
cout << "The sorted array are:" << endl;
for (int k = 0; k<len; k++)
cout << array[k] << ",";
cout << endl;
return 0;
}
基本排序算法--冒泡排序
最新推荐文章于 2022-11-23 10:40:05 发布