冒泡排序(C/C++)

#include <iostream>

using namespace std;

int main(void)
{
    int beauties[] = { 2, 1, 4, 6, 8, 5, 9, 7, 5 };

    int len = sizeof(beauties) / sizeof(beauties[0]);
    int test = 0;
  

for (int j = 0; j < len ; j++) { for (int i = 0; i < len-1; i++) { if (beauties[i] > beauties[i + 1]) { test = beauties[i]; beauties[i] = beauties[i + 1]; beauties[i + 1] = test; } } }
//cout << "------------------------------------" << endl; for (int i = 0; i < len; i++) { cout << beauties[i] << "\t"; } cout << endl; cin.get(); return 0; }

 

posted @ 2022-02-02 11:31  乐吴  阅读(30)  评论(0编辑  收藏  举报