Created
February 27, 2019 07:55
-
-
Save IJEMIN/e801eeca98107e065fdc87fb54fddd72 to your computer and use it in GitHub Desktop.
Algorithm practice
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
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