How to print a vector of integers in the form of a heap?

0

Well, I'd like to know how to implement a function in language C, that given any integer vector (int v [] = {3,4,2,1,6,7}), it can print the vector as a heap.

Ex:

    
asked by anonymous 05.08.2018 / 01:47

1 answer

0

link

This link has the library of heap.c and .h that I implemented in college, then just do the following:

    int i,v[5]={7, 6,3,9,10};
    char str[50];
    heap* NomeHeap=heap_nova(10);
    for(i=0; i<5; i++)
    {
        sprintf(str, "%d", v[i]);
        heap_insere(NomeHeap, str , -v[i]);// - ordena por ordem decrescente, com + ordena por ordem crescente
    }
    for(i=0; i<5; i++)
        printf("%s ", heap_remove(NomeHeap));

Heap.h has everything commented on.

    
05.08.2018 / 02:04