Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C# Bubble Sort
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { int[] arr = { 5, 8, 1, 8, 4, 5, 6, 5, 4 }; Console.WriteLine("Bubble Sort"); Console.Write("Start array: "); arr.ToList().ForEach(x => Console.Write(x + " ")); //sort int temp; for(int i = 0; i < arr.Length - 1; i++) { for(int j = 0; j < arr.Length - (1 + i); j++) { if(arr[j] > arr[j + 1]) { temp = arr[j + 1]; arr[j + 1] = arr[j]; arr[j] = temp; } } } Console.Write("\nSorted array: "); arr.ToList().ForEach(x => Console.Write(x + " ")); } } }
run
|
edit
|
history
|
help
1
SpawnController
Max occured character in a string
sdfrgthyjuiloiujyhtgrf
Custom thousand separator
Daily Coding Problem: Problem #4
priya
asxsv sdsd
merge 2 sorted array
Interface IEnumerable
Struct Ejemplo