IMPLEMENTATION OF HEAP SORT
PROGRAM:
#include
#include
#include
#define MAX 10
void main()
{
int i,n;
int arr[MAX];
void makeheap(int arr[MAX],int n);
void heapsort(int arr[MAX],int n);
void display(int arr[MAX],int n);
clrscr();
for(i=0;i
printf("\n How many elements you want to sort");
scanf("%d",&n);
printf("Enter the elements");
for(i=0;i
printf("\n The elements are....");
display(arr,n);
makeheap(arr,n);
printf("\n Heapified");
display(arr,n);
heapsort(arr,n);
printf("\n Elements sorted by heapsort");
display(arr,n);
getch();
}
void makeheap(int arr[MAX],int n)
{
int i,val,j,father;
for(i=1;i
val=arr[i];
j=i;
father=(j-1)/2;
while(j>0&&arr[father]
arr[j]=arr[father];
j=father;
father=(j-1)/2;
}
arr[j]=val;
}
}
void heapsort(int arr[MAX],int n)
{
int i,k,temp,j;
for(i=n-1;i>0;i--)
{
temp=arr[i];
arr[i]=arr[0];
k=0;
if(i==1)
j=-1;
else
j=1;
if(i>2&&arr[2]>arr[j])
j=2;
while(j>=0&&temp
arr[k]=arr[j];
k=j;
j=2*k+1;
if(j+1<=i-1&&arr[j]
if(j>i-1)
j=-1;
}
arr[k]=temp;
}
}
void display(int arr[MAX],int n)
{
int i;
for(i=0;i
}
OUTPUT:
How many elements you want to sort 5
Enter the elements
9
8
7
6
5
The elements are....
9
8
7
6
5
Heapified
9
8
7
6
5
Elements sorted by heapsort
5
6
7
8
9
CIET college Programs,LAB Programs for Engineering Students,DAA LAB Programs,DSA LAB Programs,Remoboys,karthik,Remokn,Student3k,programs source code,Design Analysis And Algorithms LAB Programs,Data Structures and Algorithms LAB Programs,LAB Codings,Coimbatore Institute of Engineering and Technology ( CIET )
Wednesday, September 22, 2010
IMPLEMENTATION OF HEAP SORT Programs
9:32 AM
Karthikh Venkat
Popular Posts( Last 7 Days )
-
Amazing Sky Wallpaper Super Sea Sky Wallpaper Super Orange Sky Wallpaper Super Mounten Sky Wallpaper Super Blue Sky Wallpaper ...
-
விஜய்- அதிர்ச்சி தரும் எஸ்.எம்.எஸ் ஜோக்ஸ். 1. இயக்குநர் ஷங்கர் - நான் இதுவரைக்கும் எடுத்த எல்லா படங்களும் சூப்பர் ஹிட்ஸ்,ஒரு படம் கூட இது வ...
-
Indian Premier League 2011 – Auction Chennai Super Kings No. of players bought : 18 (8 Indian, 10 foreign) Money spent : $8.6 mi...
-
RAM is an abbreviation for Random Access Memory. It usually refers to "temporary" memory, as when the system is shut down, the mem...
-
Hot Priyamani images,Sexy priyamani pictures,priyamani wallpapers. Hot Priyamani images, pictures, Priyamani sexy stills, priyamani gallery,...
-
Tamil Movie Yudham Sei Mp3 Songs Free Download, Yudham Sei Audio Songs Download,Udham sei songs Yudham Sei Movie Details: Banner: Sony Mu...
