summaryrefslogtreecommitdiff
path: root/week2/Bubblesort.cs
diff options
context:
space:
mode:
Diffstat (limited to 'week2/Bubblesort.cs')
-rw-r--r--week2/Bubblesort.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/week2/Bubblesort.cs b/week2/Bubblesort.cs
new file mode 100644
index 0000000..82ceb4f
--- /dev/null
+++ b/week2/Bubblesort.cs
@@ -0,0 +1,19 @@
+namespace ALGA {
+ public class Bubblesort {
+ public static void bubblesort(ISortList list) {
+ for (int i = 0; i < list.Count - 1; i++) {
+ bool swapped = false;
+
+ for (int j = 0; j < list.Count - i - 1; j++) {
+ if (list.compare(j, j + 1) <= 0) continue;
+
+ list.swap(j, j + 1);
+ swapped = true;
+ }
+
+ if (!swapped) break;
+ }
+ }
+ }
+}
+