Skip to content

Instantly share code, notes, and snippets.

@hsynkrcf
Created June 21, 2024 00:37
Show Gist options
  • Save hsynkrcf/008174c706f102865906d5e899206be0 to your computer and use it in GitHub Desktop.
Save hsynkrcf/008174c706f102865906d5e899206be0 to your computer and use it in GitHub Desktop.
Insertion Sort Algorithm Performed On C#
public int[] InsertionSort(int[] arr)
{
int n = arr.Length;
for (int i = 1; i < n; ++i)
{
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment