Skip to content

Instantly share code, notes, and snippets.

@deepumi
Last active June 14, 2019 13:39
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 deepumi/53a8476f30cf3f19e8981b22922314d0 to your computer and use it in GitHub Desktop.
Save deepumi/53a8476f30cf3f19e8981b22922314d0 to your computer and use it in GitHub Desktop.
Insertion Sort
string[] arr = { "orange", "nest", "apple", "ABC","xyz", "bana", "cat"};
for (int i = 0; i < arr.Length; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i]?.CompareTo(arr[j]) > 0)
{
var temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment