From 9bc55aea98468166f648952bf27d05450e87c901 Mon Sep 17 00:00:00 2001 From: newde Date: Mon, 2 Feb 2026 11:12:34 -0500 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8C260202=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 260202/冒泡排序.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 260202/冒泡排序.cpp 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; +}