aboutsummaryrefslogtreecommitdiff
path: root/tests/sysy_lvX/bubble_sort.sy
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
committerRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
commit4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch)
treea5922559836e45fb3459a3d070367912e1035b1a /tests/sysy_lvX/bubble_sort.sy
downloadrcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.gz
rcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.xz
Set up a git repoHEADmaster
Diffstat (limited to 'tests/sysy_lvX/bubble_sort.sy')
-rwxr-xr-xtests/sysy_lvX/bubble_sort.sy51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/sysy_lvX/bubble_sort.sy b/tests/sysy_lvX/bubble_sort.sy
new file mode 100755
index 0000000..2aae5d6
--- /dev/null
+++ b/tests/sysy_lvX/bubble_sort.sy
@@ -0,0 +1,51 @@
+int arr[100];
+
+void bubbleSort(int n)
+{
+ int i = 0;
+ int j = 0;
+ int tmp;
+
+ while (i < n - 1)
+ {
+ j = 1;
+ while (j < n)
+ {
+ if (arr[j] < arr[j - 1])
+ {
+ tmp = arr[j];
+ arr[j] = arr[j - 1];
+ arr[j - 1] = tmp;
+ }
+ j = j + 1;
+ }
+ i = i + 1;
+ }
+}
+
+void printArray(int n)
+{
+ int i = 0;
+ while (i < n)
+ {
+ putint(arr[i]);
+ putch(32);
+ // printf("%d ", arr[i]);
+ i = i + 1;
+ }
+}
+
+int main()
+{
+ int n;
+ int i = 0;
+ n = getint();
+ while (i < n)
+ {
+ arr[i] = getint();
+ i = i + 1;
+ }
+ bubbleSort(n);
+ printArray(n);
+ return 0;
+} \ No newline at end of file