Hello again,

I am working on a heap program :)

The code will let the user insert numbers and then print them in order, starting with the largest number. In the end, the heap will be empty once the last number is printed.

My problem is, that the heap is not sorted. The parent is supposed to be greater than the children. People tell me that the swap is not working:

Code:
void heapify(heap* h, size_t i)
{ 
    if (largest != i)
    {
        int tmp = h -> elements[i];
        h -> elements[i] = h -> elements[largest];
        h -> elements[largest] = tmp;
        heapify(h, largest);
    }
}
I feel pretty stupid for not seeing it but I don't know what I am doing wrong in this section.

Also, it doesn't print the largest number. That would be this section:
Code:
int heap_extract_max(heap* h) 
{
    int max;
    if (h -> size < 1)
    {
        printf("Heap is empty!\n");
        return(-1);
    }
    else
    {
        max = h -> elements[0];
        h -> elements[0] = h -> elements[h -> size[h -> elements]];
        h -> size[h -> elements] = h -> size - 1;
        heapify(h, 0);
        return max;
    }
}
I am happy about any kind of help! :)
Feel free to ask me about other parts of the code. I didn't want to post the whole code so I tried to minimize it on the problems but as a newbie I could be wrong of course.