编程语言
首页 > 编程语言> > 冒泡排序(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; }

 

标签:beauties,int,C++,len,++,冒泡排序,test,sizeof
来源: https://www.cnblogs.com/WU20/p/15860170.html