Created
June 26, 2020 01:01
-
-
Save AbhinavPradeep/04eadb64d75c6c91ea729e3c203d96c4 to your computer and use it in GitHub Desktop.
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.Diagnostics; | |
namespace SortingArrays | |
{ | |
class BubbleSort | |
{ | |
public void Sort(int[] input) | |
{ | |
var watch = Stopwatch.StartNew(); | |
try | |
{ | |
for (int i = 0; i <= input.Length - 2; i++) | |
{ | |
for (int j = 0; j <= input.Length - 2; j++) | |
{ | |
if (input[j] > input[j + 1]) | |
{ | |
int Temp = input[j]; | |
input[j] = input[j + 1]; | |
input[j + 1] = Temp; | |
} | |
} | |
} | |
watch.Stop(); | |
} | |
finally | |
{ | |
PrintArray printArray = new PrintArray(); | |
printArray.PrintIntegerArray(input); | |
Console.WriteLine($" Bubble Sort executed in {watch.ElapsedTicks} ticks"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment