Skip to content

Instantly share code, notes, and snippets.

@AbhinavPradeep
Created June 26, 2020 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhinavPradeep/04eadb64d75c6c91ea729e3c203d96c4 to your computer and use it in GitHub Desktop.
Save AbhinavPradeep/04eadb64d75c6c91ea729e3c203d96c4 to your computer and use it in GitHub Desktop.
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