Posted By

Insertion Sort Program in C

Education 55

#include<stdio.h>

int main()


{       

    int i, j, temp;    

    int size=10;     

    int number[10] = {9, 10, 13, 14, 61, 17, 91, 11, 21, 3};         


    for(i=1;i<size;i++){

        temp=number[i];

        j=i-1;

        while((temp<number[j])&&(j>=0)){

            number[j+1]=number[j];

            j=j-1;

        }

        number[j+1]=temp;

    }      


printf("Sorted elements by Using Insertion Sort: ");     


    for(i=0;i<size;i++)

        printf(" %d",number[i]);       

    return 0;  

Topics: Algorithm Insertion Sort

Insertion Sort Program in C

Login to comment login

Latest Jobs