From 54c82a2731c40368c8c2eceb7abcb24165412c36 Mon Sep 17 00:00:00 2001
From: h2-addad <hamza2.addad@live.uwe.ac.uk>
Date: Sun, 16 Jul 2023 00:47:45 +0000
Subject: [PATCH] Update

---
 src/examples/bubsort.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 src/examples/bubsort.c

diff --git a/src/examples/bubsort.c b/src/examples/bubsort.c
new file mode 100644
index 0000000..df51a2f
--- /dev/null
+++ b/src/examples/bubsort.c
@@ -0,0 +1,38 @@
+/* sort.c
+
+   Test program to sort a large number of integers.
+
+   Intention is to stress virtual memory system.
+
+   Ideally, we could read the unsorted array off of the file
+   system, and store the result back to the file system! */
+#include <stdio.h>
+
+/* Size of array to sort. */
+#define SORT_SIZE 128
+
+int
+main (void)
+{
+  /* Array to sort.  Static to reduce stack usage. */
+  static int array[SORT_SIZE];
+
+  int i, j, tmp;
+
+  /* First initialize the array in descending order. */
+  for (i = 0; i < SORT_SIZE; i++)
+    array[i] = SORT_SIZE - i - 1;
+
+  /* Then sort in ascending order. */
+  for (i = 0; i < SORT_SIZE - 1; i++)
+    for (j = 0; j < SORT_SIZE - 1 - i; j++)
+      if (array[j] > array[j + 1])
+	{
+	  tmp = array[j];
+	  array[j] = array[j + 1];
+	  array[j + 1] = tmp;
+	}
+
+  printf ("sort exiting with code %d\n", array[0]);
+  return array[0];
+}
-- 
GitLab