HEAP - printf("Enter the nos");...

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 display(int a[],int n) { int i; printf("\nLIST\n"); for(i=0;i<n;i++) printf("%d ",a[i]); } void hsort(int x[],int n) { int i,s,f,elt,ivalue,z; 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; } printf("\nList:"); for(i=0;i<n;i++) printf("%d ",x[i]); 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=(s*2)+1; if((s+1<=i-1)&&(x[s]<x[s+1]))
Background image of page 1

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

View Full DocumentRight Arrow Icon
s++; if(s>i-1) s=-1; } x[f]=ivalue; printf("\nList:"); for(z=0;z<n;z++) printf("%d ",x[z]); printf("\tkey=%d",ivalue); } } void main() { int n,i,arr[50]; clrscr(); printf("Enter the no of data:"); scanf("%d",&n);
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: 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 1 Enter the no of data:9 Enter the nos5 2 10 4 3 9 7 8 6 E LIST 5 2 10 4 3 9 7 8 6 List:10 8 9 6 3 5 7 2 4 List:9 8 7 6 3 5 4 2 #10 key=4 List:8 7 5 6 3 2 4 #9 10 key=2 List:7 6 5 4 3 2 #8 9 10 key=4 List:6 5 2 4 3 #7 8 9 10 key=2 List:5 4 2 3 #6 7 8 9 10 key=3 List:4 3 2 #5 6 7 8 9 10 key=3 List:3 2 #4 5 6 7 8 9 10 key=2 List:2 #3 4 5 6 7 8 9 10 key=2 LIST 2 3 4 5 6 7 8 9 10 2 */ *...
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 - printf("Enter the nos");...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online