Created
March 9, 2016 04:04
-
-
Save ahmedengu/2c8b9a2bcf756b36333f 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
#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