#include<iostream>
using namespace std;

void bubbleArr(int *arr,int len)
{
    for (int i = 0; i < len - 1; i++)
    {
        for (int j = 0; j < len - i - 1; j++)
        {
            if (arr[j] > arr[j + 1]) 
            {
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
}

void outputArr(int *arr,int len)
{
    for (int i = 0; i < len; i++)
        cout << arr[i] << " ";
    cout << endl;
}


int main()
{
    int arr[] = { 3,6,7,5,1,0,9,8,4,2 };
    int len = sizeof(arr) / sizeof(arr[0]);

    cout << "原来数组为:" << endl;
    outputArr(arr, len);

    bubbleArr(arr, len);
    
    cout << "冒泡排序后的数组为:" << endl;
    outputArr(arr, len);
    
    system("pause");
    return 0;

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2022-02-01
  • 2022-12-23
  • 2021-08-22
  • 2021-10-19
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案