on-internet
← Community

building a bottomUp heap

Stack Overflow ·

im trying to do a heap bottom up construction from Psuedo code from my text book however the output im getting is not a correct heap im getting out 2 9 8 6 5 7 anyone know where im going wrong(pseudo code is from a text book, and heap needs to be array) here is the PsuedoCode bottom up im working with //constructs a heap from elements of a given array by bottom up algorithm //input an array H[1...n] of orderable items //output a heap H[1...n] for i<- [n/2] downto 1 do k<-i; v<-H[k]; heap<-False while not heap and 2*k <= n do j<-2*k if(j<n) //there are two children if H[j] < H[j+1] j<- j+1 if v

Comments

Sign in or sign up to comment and upvote.

No comments yet.