Skip to content

Instantly share code, notes, and snippets.

@ahmedengu
Created March 9, 2016 04:04
Show Gist options
  • Save ahmedengu/2c8b9a2bcf756b36333f to your computer and use it in GitHub Desktop.
Save ahmedengu/2c8b9a2bcf756b36333f to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void insertionSort() {
int arr[] = {1,5,9,8,9,4,7,5,6,3,1,7};
int size=12;
int i,j;
for (i = 1; i < size; i++)
{
for (j = i; j >= 1; j--)
{
if (arr[j] < arr[j-1])
{
arr[j] += arr[j-1];
arr[j-1] = arr[j] - arr[j-1];
arr[j] -= arr[j-1];
}
else
break;
}
}
for (int i = 0; i < size; i++) {
cout<<arr[i] <<((i==size-1)?"":" ,");
}}
int main() {
insertionSort();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment