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) { /* Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. */ int []arr = { 12, 19, 15, 8, 4, 6, 3, 29, 9, 2, 22, 44, 20, 25 }; bubbleSort(arr); Console.WriteLine("Sorted array"); Display(arr); } static void bubbleSort(int []arr) { int n = arr.Length; for (int i = 0; i <= n - 2; i++) for (int j = 0; j <= n - 2; j++) if (arr[j] > arr[j + 1]) { // swap int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } static void Display(int []arr) { int n = arr.Length; for (int i = 0; i < n; ++i) Console.Write(arr[i] + " "); Console.WriteLine(); } } }
run
|
edit
|
history
|
help
0
Basic
3. Delegates and events, reference pitfall
Puzz1
Variables
Simple StackOverflowException
Find the value of a specific span in an html script
online compiler
z
Delegate-ModifyObject
Homework3