冒泡排序(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; }

 

上一篇:C语言指针详解


下一篇:memset的使用