diff --git a/260202/冒泡排序.cpp b/260202/冒泡排序.cpp new file mode 100644 index 0000000..0cc3cd1 --- /dev/null +++ b/260202/冒泡排序.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int main() { + int a[5] = {8,114,24,88,5}; // һ򵥵 + int n = 5; + + // ð߼ + for (int i = 0; i < n - 1; i++) { // ѭƱȽ + for (int j = 0; j < n - 1 - i; j++) { // ڲѭȽ + if (a[j] > a[j + 1]) { // ǰıȺĴ + // λ + int temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } + + // + cout << ": "; + for (int i = 0; i < n; i++) { + cout << a[i] << " "; + } + + return 0; +}