any 1 noe ab make_heap() ?

Jan 23, 2008 at 4:27pm
i found an example below; it is ab the make_heap() but, it is not working due to the "print" function.

i doubt ab it. Can any 1 explain more detail to me how to use make_heap()?thx^^
1
2
3
4
5
6
int main(){
int a[]={44,88,33,77,11,99,66,22,55};
print(a,9);
make_heap(a,a+9);
print(a,9);
}
Jan 23, 2008 at 5:26pm
make_heap rearranges the elements between the pointers passed as parameters as a heap, i.e. with the first element being the higher one in value.

in your example (and ignoring the prints), after the call to make_heap, the elements in the a[] array would be rearranged in such a way that a[0] would be 99

For more info check the reference:

http://cplusplus.com/make_heap
Topic archived. No new replies allowed.