# Heap Sort - } x[f]=ivalue; } } void display(int a,int n) {...

This preview shows pages 1–3. Sign up to view the full content.

#include<stdio.h> #include<conio.h> /* RISHI AGARWAL             HEAP SORT    ROLL NO 02    SE CMPN A */ void hsort(int x[],int n) {  int i,s,f,elt,ivalue;  for(i=1;i<n;i++)  {   elt=x[i];   s=i;   f=(s-1)/2;   {    x[s]=x[f];    s=f;    f=(s-1)/2;   }   x[s]=elt;  }  for(i=n-1;i>0;i--)  {   ivalue=x[i];   x[i]=x[0];   f=0;   if(i==1)   s=-1;   else   s=1;   s=2;   {    x[f]=x[s];    f=s;    s=(2*f)+1;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
s++;    if(s>i-1)    s=-1;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } x[f]=ivalue; } } void display(int a,int n) { int i; printf("\nLIST\n"); for(i=0;i<n;i++) printf("%d ",a[i]); } void main() { int n,i,arr[50]; clrscr(); printf("Enter the no of data:"); scanf("%d",&n); printf("Enter the nos"); for(i=0;i<n;i++) scanf("%d",&arr[i]); //Displaying List display(arr,n); //Heap Sort hsort(arr,n); //Displaying Sorted List display(arr,n); getch(); } OUTPUT: Enter the no of data:5 Enter the nos5 4 3 2 1 LIST 5 4 3 2 1 LIST 1 2 3 4 5...
View Full Document

## This note was uploaded on 10/25/2010 for the course CMPN SEM4 taught by Professor Thakur during the Spring '07 term at University of Mumbai.

### Page1 / 3

Heap Sort - } x[f]=ivalue; } } void display(int a,int n) {...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online