know the personalities
hold your mouse,move left and right

Share Our Page Contents

DataStructure-Insertion sort.

DataStructure-Insertion sort.

#include <stdio.h>
#include <conio.h>
void main( )
{
int arr[5] = { 25, 17, 31, 13, 2 } ;
int i, j, k, temp ;
clrscr( ) ;
printf ( "Insertion sort.\n" ) ;
printf ( "\nArray before sorting:\n") ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;
for ( i = 1 ; i <= 4 ; i++ )
{
for ( j = 0 ; j < i ; j++ )
{
if ( arr[j] > arr[i] )
{
temp = arr[j] ;
arr[j] = arr[i] ;
for ( k = i ; k > j ; k-- )
arr[k] = arr[k - 1] ;
arr[k + 1] = temp ;
}
}
}
printf ( "\n\nArray after sorting:\n") ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;
getch( ) ;
}

Free Projects
Java Projects
Engineering Projects
Science Projects
C/C++/.NET/Oracle Projects
Wipro Placement Papers
TCS Placement Papers
Infosys Placement Papers
Syntel Placement Papers
I-Gate Placement Papers

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com