Last active
October 4, 2016 19:24
-
-
Save swarupsro/76dc6623b871553cfddb359e9b5ca068 to your computer and use it in GitHub Desktop.
Insertion Sort
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 <stdio.h> | |
int main() | |
{ | |
int A[20], n, k, i, loc, temp; | |
A[0] = -32768; | |
printf("Enter the number of elements: "); | |
scanf("%d",&n); | |
printf("\n Input %d Integers: ", n); | |
for(i=1; i<=n; i++) | |
scanf("%d", &A[i]); | |
for(k=2; k<=n; k++) | |
{ | |
temp = A[k]; | |
loc = k-1; | |
while(temp < A[loc]) | |
{ | |
A[loc+1] = A[loc]; | |
loc--; | |
} | |
A[loc+1] = temp; | |
} | |
printf("\n\nSorted elements are : \n"); | |
for(i=1; i<=n; i++) | |
printf("%d\t",A[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment