Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bubble sort
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var coll = new int[]{1,4,5,2,4,7,8,9,4,2,6,7}; var count = Sort(coll); //Your code goes here foreach(var i in coll){ Console.WriteLine(i); } Console.WriteLine("Counter:" + count); } public static int Sort(int[] coll) { var counter = 0; var len = coll.Length; for(var i = 0; i < len; i++){ var isSorted = true; for(var j = 0; j < len - i - 1; j++){ if(coll[j] > coll[j+1]){ counter++; Swap(ref coll[j], ref coll[j+1]); isSorted = false; } } if(isSorted) break; } return counter; } private static void Swap(ref int i, ref int j){ var temp = i; i = j; j = temp; } } }
run
|
edit
|
history
|
help
0
generics one more doubt-stack overflow exception
bro
x=msgbox("Your Message Here", Button+Icon, "Your Title Here")
Fechas
How to find the fisrt index of a substring in a given string?
Helloworld
Testing
Order of Ops 4.2
Hello,rakib!
MockTest