You are on page 1of 3

INSERTION SORTING

#include<iostream.h>
#include <stdio.h>
#include<conio.h>
#include <time.h>
int main ( )
{
clock_t start, end;
int arr[5];
int a,b,c,d,temp ;
clrscr();
start = clock();
cout<<"******************";
cout<<"\n* Insertion Sort *";
cout<<"\n******************";
cout<<"\nEnter Array:\n";
for(a=0;a<5;a++)
cin>>arr[a];
for (b=1;b<5;b++)
{
for (c=0;c<b;c++)
{
if ( arr[c] > arr[b] )
{
temp = arr[c] ;
arr[c] = arr[b] ;
for (d=b;d>c;d--)
arr[d]=arr[d-1] ;
arr[d+1]=temp ;
}
}
}
printf ( "\nResult:\n") ;
for (b=0;b<5;b++)
{
cout<<arr[b];
cout<<" ";
}
end = clock();
printf("\n\nTime count: %0.9f seconds",(end-start)/CLOCKS_PER_SEC);
getch();
return 0;
}
BUBBLE SORTING
#include<iostream.h>
#include <stdio.h>
#include<conio.h>
#include <time.h>

int main ( )
{
clock_t start, end;
int array[5];
int a,b,temp;
clrscr();
start = clock();
cout<<"\n******************";
cout<<"\n* Bubble Sort *";
cout<<"\n******************";
cout<<"\nEnter Array:\n";
for(a=0;a<5;a++)
cin>>array[a];
for(a=0;a<5;a++)
{
for(b=0;b<a;b++)
{
if(array[a]<array[b])
{
int temp=array[a];
array[a]=array[b];
array[b]=temp;
}
}
}
printf ( "\nResult:\n") ;
for (b=0;b<5;b++)
{
cout<<array[b];
cout<<" ";
}
end = clock();
printf("\n\nTime count: %0.9f seconds",(end-start)/CLOCKS_PER_SEC);
getch();
return 0;
}

You might also like