Other Type Of Sorting : Click here :: most important ::
#include<iostream.h>
#include<conio.h>
void display(int *arr,int n)
{
cout<<endl;
for(int i=0;i<=n;i++){
cout<<arr[i]<<"\t"; }
cout<<endl;
}
void shellsort(int *arr,int n)
{
int gap,i,j,temp;
for(gap=n/2;gap>0;gap/=2)
{
for(i=gap;i<=n;i++)
{
for(j=i-gap;j>=0 && arr[j]>arr[j+gap];j-=gap)
{
display(arr,n);
temp=arr[j];
arr[j]=arr[j+gap];
arr[j+gap]=temp;
}
}
}
}
void main()
{
int x[]={12,7,3,8,1,5,2};
clrscr();
display(x,6);
shellsort(x,6);
display(x,6);
getch();
}
#include<iostream.h>
#include<conio.h>
void display(int *arr,int n)
{
cout<<endl;
for(int i=0;i<=n;i++){
cout<<arr[i]<<"\t"; }
cout<<endl;
}
void shellsort(int *arr,int n)
{
int gap,i,j,temp;
for(gap=n/2;gap>0;gap/=2)
{
for(i=gap;i<=n;i++)
{
for(j=i-gap;j>=0 && arr[j]>arr[j+gap];j-=gap)
{
display(arr,n);
temp=arr[j];
arr[j]=arr[j+gap];
arr[j+gap]=temp;
}
}
}
}
void main()
{
int x[]={12,7,3,8,1,5,2};
clrscr();
display(x,6);
shellsort(x,6);
display(x,6);
getch();
}
1 comments
thankx its help full :)
ReplyDelete