insertionSort in c language

 

Insertion sort in c language

 Note : it is completely based on sorting in ascending order

 


Implementing code

#include<stdio.h>

 int main()

 {

    int i,j,arr[100],temp, count; // declaration variables

    printf("enter the of size elements: ");

    scanf("%d",&count);

    printf("enter the elements in array : ");

    for(i=0;i<count;i++)  // inserting elements

    {

        scanf("%d",&arr[i]);// storing the elements i array

    }

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

    {

        temp=arr[i];   //array values storing in temp variable

        j=i-1;      //decreementing the values of 'i' and it will storing in j variable

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

        {

            arr[j+1]=arr[j];

            j=j-1;

        }

        arr[j+1]=temp;

    }

    printf("sorted element : "); // printing the elements

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

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

    return 0;

 }

                       Output:


 

 



Comments

Popular posts from this blog

Scipy Library overview

python seaborn library