answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

int a[25],n,i;

void maxheapify(int,int);

void buildmaxheap();

void main()

{

int temp;

clrscr();

printf("\n\t\t\t\tHEAP SORT");

printf("\n\t\t\t\t**** ****\n\n\n");

printf("\n Enter no of elements:");

scanf("%d",&n);

printf("\n Enter elements to be sorted\n\n");

for(i=1;i<=n;i++)

scanf("%d",&a[i]);

buildmaxheap();

for(i=n;i>=2;i--)

{

temp=h[1];

a[1]=a[i];

a[i]=temp;

maxheapify(1,i-1);

}

printf("\n SORTED ELEMENT\n\n");

for(i=1;i<=n;i++)

printf("%d\n",a[i]);

getch();

}

void buildmaxheap()

{

int i;

for(i=n/2;i>=1;i--)

maxheapify(i,n);

}

void maxheapify(int i,int n)

{

int j,element;

j=2*i;

element=a[i];

while(j<=n)

{

if((j<n)&&(a[j]<a[j+1]))

j=j++;

if(element>=a[j])

break;

a[j/2]=a[j];

j=2*j;

}

a[j/2]=element;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Write a program of binary heap in c or c language?

to implement operations on binary heap in c


What is the C program for heap sort using recursion?

123


Different types of sorting techniques in c language?

types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort


C code to implement the file allocation algorithm?

yes we can do it,in c


C memory model?

Memory Organization for a process -------------------------------------------- CODE SEGMENT: contains executable code DATASEGMENT:contains static and global variable HEAP SEGMENT:Dynamically allocated variables will be in heap STACK SEGMENT:For local or automatic variables PREM G premgnath@gmail.com


What bank has sort code 62-31-31?

eccount c


What is the basic structure of ram?

ram have divided into five part a) heap b)satck c)code d)global e) unpatition space


What is the VHDL code to implement NOR gate?

Below code can implement NOT gate in VHDL. The code is written in data flow model. Library ieee; use ieee.std_logic_1164.all; Entity gates is port (a : in std_logic; c : out std_logic); end gates ; architecture and1 of gates is begin c&lt;=not a; end and1;


What is VHDL code to implement AND gate?

Below code can implement AND gate in VHDL. The code is written in data flow model. Library ieee; use ieee.std_logic_1164.all; Entity gates is port (a,b : in std_logic; c : out std_logic); end gates ; architecture and1 of gates is begin c&lt;=a and b; end and1;


What is the VHDL code to implement NAND gate in behavioral model?

Below code can implement NAND gate in VHDL. The code is written in behavioral model. Library ieee; use ieee.std_logic_1164.all; Entity gates is port (a,b : in std_logic; c : out std_logic); end gates ; architecture and1 of gates is begin process(a,b) Begin If (a=1 and b=1) then C&lt;='0'; Else C&lt;= '1'; End if; End process; End and1;


What is the VHDL code to implement NOR gate in behavioral model?

Below code can implement NAND gate in VHDL. The code is written in data flow model. Library ieee; use ieee.std_logic_1164.all; Entity gates is port (a,b : in std_logic; c : out std_logic); end gates ; architecture and1 of gates is begin c&lt;=a nand b; end and1;


Where the heap memory is allocated in c?

Main Memory (RAM).