Here we gave easiest understanding program to you.
All programs easy to learn every person.
And all subjects are compulsory in BCA.
Powered by Blogger.

Followers

Friday, 20 September 2019

Insertion Sort

0 comments


  Various Sorting techniques available in Data Structure

1. Bubble Sort
2. Insertion Sort
3. Merge Sort
4. Quick Sort
5. Heap Sort
6. Selection Sort





/* c program to implement insertion sort */
        


                
                                                      BCA Course


#include<stdio.h>
int main()
{
    int a[50],n,i,j,temp;
    printf("enter n value:");
    scanf("%d",&n);
    printf("Enter %d numbers:",n);
     for(i=0;i<n;i++)
      scanf("%d",&a[i]);
       for(i=0;i<n;i++)
    {
       temp=a[i];
       for(j=i; j>0 && a[j-1]>temp; j--)
           a[j]=a[j-1];
           a[j]=temp;
    }
    printf("Sorted array is:");
     for(i=0;i<n;i++)
       printf("%d\t",a[i]);
    return 0;
}

Output:-

enter n value:5
Enter 5 numbers:9  5  8  2  10
Sorted array is:2   5    8   9   10

                        
  

No comments:

Post a Comment