From 8840e665ea22c7701b597db55ad0ba8d20fd3ac8 Mon Sep 17 00:00:00 2001 From: dvir019 <30556126+dvir019@users.noreply.github.com> Date: Sat, 9 Oct 2021 12:45:32 +0300 Subject: [PATCH] Create BubbleSort.cs Bubble sort in C#. --- csharp/BubbleSort.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 csharp/BubbleSort.cs diff --git a/csharp/BubbleSort.cs b/csharp/BubbleSort.cs new file mode 100644 index 00000000..ae1fa07d --- /dev/null +++ b/csharp/BubbleSort.cs @@ -0,0 +1,17 @@ +class BubbleSort +{ + public static void BubbleSort(int[] arr) + { + int n = arr.Length; + for (int i = 0; i < n - 1; i++) + for (int j = 0; j < n - i - 1; j++) + { + if (arr[j] > arr[j + 1]) + { + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } +}