Skip to content

Instantly share code, notes, and snippets.

@IJEMIN
Created February 27, 2019 07:55
Show Gist options
  • Save IJEMIN/e801eeca98107e065fdc87fb54fddd72 to your computer and use it in GitHub Desktop.
Save IJEMIN/e801eeca98107e065fdc87fb54fddd72 to your computer and use it in GitHub Desktop.
Algorithm practice
using System;
using System.Collections;
public class Program
{
public static void Main()
{
Action<int[]> bubleSort = (int[] list) => {
bool again = false;
int limit = list.Length;
do {
again = false;
for(var i = 0; i < limit; i++) {
var currentValue = list[i];
var nextValue = i + 1 < limit ? list[i+1] : int.MaxValue;
if(nextValue < currentValue) {
list[i] = nextValue;
list[i+1] = currentValue;
again = true;
}
}
} while(again);
};
int[] randomList = new int[] {23,1,5,16,42,15,4,16,8};
bubleSort(randomList);
Console.WriteLine(string.Join(", ", randomList));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment