Headlines News :
Home » , » Shorting of Array using insertion short

Shorting of Array using insertion short

Written By Durgesh on Thursday 1 March 2012 | 07:27

i am posting a shorting of array by using insertion short here logic behind insertion short id that  first element will compare with second and if first element is grater then second it will swap lets we know this by this image tutorial

let we see how we can implement in our program


#include<stdio.h>
void main()
{
 int A[20], N, Temp, i, j;
 clrscr();
 printf("\n\n\t ENTER THE NUMBER OF TERMS...: ");
 scanf("%d", &N);
 printf("\n\t ENTER THE ELEMENTS OF THE ARRAY...:");
 for(i=0; i<N; i++)
 {
  gotoxy(25,11+i);
  scanf("\n\t\t%d", &A[i]);
 }
 for(i=1; i<N; i++)
 {
  Temp = A[i];
  j = i-1;
  while(Temp<A[j] && j>=0)
  {
   A[j+1] = A[j];
   j = j-1;
  }
  A[j+1] = Temp;
 }
 printf("\n\tTHE ASCENDING ORDER LIST IS...:\n");
 for(i=0; i<N; i++)
  printf("\n\t\t\t%d", A[i]);
 getch();
}
Share this article :

No comments:

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Tutorial of Programing - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger