{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Heap Sort - x[f]=ivalue void display(int a,int n int i...

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

View Full Document Right Arrow Icon
#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;   while(s>0&&x[f]<elt)   {    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;   if(i>2&&x[2]>x[1])   s=2;   while(s>=0&&ivalue<x[s])   {    x[f]=x[s];    f=s;    s=(2*f)+1;
Background image of page 1

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

View Full Document Right Arrow Icon
   if((s+1<=i-1)&&(x[s]<x[s+1]))    s++;    if(s>i-1)    s=-1;
Background image of page 2
Background image of page 3
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

  • Spring '07
  • THAKUR
  • #include, RISHI AGARWAL, 02    SE CMPN, int i,s,f,elt,ivalue, RISHI AGARWAL             HEAP, */ void hsort

{[ snackBarMessage ]}