Last active
June 21, 2024 00:38
-
-
Save hsynkrcf/d7e2f6fdb77303cbeccd83a2b457f39b to your computer and use it in GitHub Desktop.
Bubble Sort Algorithm Performed On C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int[] 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; | |
} | |
} | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment