Created
September 2, 2011 16:32
-
-
Save rohit-nsit08/1189087 to your computer and use it in GitHub Desktop.
simple insertion sort
This file contains hidden or 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
| //insertion sort | |
| #include<stdio.h> | |
| int main() | |
| { | |
| int arr[5]={5,4,3,2,1}; | |
| int i,j,chose; | |
| int n = sizeof(arr)/sizeof(int); | |
| for(i=1;i<n;i++) | |
| { | |
| chose = arr[i]; // chose the ith card | |
| j=i-1; | |
| while((j>=0)&&(arr[j]>chose)) | |
| { | |
| arr[j+1] = arr[j]; | |
| j--; | |
| } | |
| arr[j+1] = chose; | |
| } | |
| for(i=0;i<n;i++) | |
| printf("%d ",arr[i]); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment