You'll rarely write sift up and sift down yourself. Python, Java and C++ each ship a heap — and JavaScript doesn't, so this course writes one small class once and reuses it everywhere. Here's each language's heap, how to make it order things your way, and the traps that cost people marks.
The same small job in all four: put some numbers in a min-heap, then take them all out. They come out smallest first.
Members only · free account
The rest of this lesson, with 4 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The is free to read, no account needed.
In the rest of this lesson