C++ 冒泡排序实现详解:代码示例及解析
#include
using namespace std;
int main() { int array[5] = {5, 8, 3, 4, 6}; int i, j, temp; for (i = 0; i < 5; i++) { for (j = 0; j < 5 - i - 1; j++) { if (array[j] > array[j + 1]) { temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } } for (i = 0; i < 5; i++) { cout << array[i] << ' '; } return 0; }
原文地址: https://www.cveoy.top/t/topic/libR 著作权归作者所有。请勿转载和采集!