C Program For Insertion Sorting

#include<stdio.h>
#include<conio.h>
void insertion_sort(int a[20],int n);
 void main()
{
    auto int n,a[20];
    register int i,j,temp;
    clrscr();
    printf("enter the size of an array");
    scanf("%d",&n);
    printf("enter array elements");
    for(i=0;i<n;i++)
scanf("%d",&a[i]);
    insertion_sort(a,n);
    printf("the sorted elements are:\n");
    for(i=0;i<n;i++)
printf("\t%d",a[i]);
    getch();
 }
  void insertion_sort(int a[20],int n)
 {
  int temp,i,j;
  for(i=1;i<n;i++)
  {
  temp=a[i];
  for(j=i;j>0&&a[j-1]>temp;j--)

     a[j]=a[j-1];
     a[j]=temp;
    // a[i+1]=temp;

 }
 }
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment