C programming

Showing posts with label insertion sort. Show all posts
Showing posts with label insertion sort. Show all posts

Friday, May 6, 2016

C program to sort an array using insertion sort

#include<stdio.h>
void main()
{
 int a[10]={1,8,6,0,6,68,44,66,45,38};
 int i,temp,k,n=10,pos;
 for(i=1;i<n;i++)
  {
   k=i-1;
   while(k>=0&&a[k]>a[k+1])
    {
     temp=a[k];
     a[k]=a[k+1];
     a[k+1]=temp;
     k--;
    }
  }
 printf("sorted array\n");
 for(i=0;i<n;i++)
  {
   printf("%d ",a[i]);
  }
}

output
sorted array
0 1 6 6 8 38 44 45 66 68
Posted by Dinesh Agrawal at 8:35 AM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: C, insertion sort, insertion sorting, sort array, sort array of integers, sort array using insertion sort, sort values, sorting
Older Posts Home
Subscribe to: Posts (Atom)

About Me

My photo
Dinesh Agrawal
View my complete profile

Blog Archive

  • ▼  2016 (61)
    • ▼  June (9)
      • C program to understand the concept of initializat...
      • C program to make two matrix dynamically and show ...
      • C program to calculate GCD (greatest common diviso...
      • C program to save and retrieve records from extern...
      • c program to find factorial of a number without us...
      • C program to select elements from three given arra...
      • c++ program to show operation on time, add seconds...
      • C program to check given number in strong number o...
      • c program to count number of 1 in binary represent...
    • ►  May (14)
    • ►  April (15)
    • ►  March (23)
Simple theme. Theme images by fpm. Powered by Blogger.