Files
java-interview-lab/heap/output/02-dry-run-sift-down.txt
T

14 lines
549 B
Plaintext

Min-heap: two poll() calls on [5, 20, 10, 35, 40, 50]
=====================================================
poll() returns 5; last value moved to root [50, 20, 10, 35, 40]
smaller child a[2]=10 < 50 swap 0 <-> 2
reached a leaf [10, 20, 50, 35, 40]
poll() returns 10; last value moved to root [40, 20, 50, 35]
smaller child a[1]=20 < 40 swap 0 <-> 1
smaller child a[3]=35 < 40 swap 1 <-> 3
reached a leaf [20, 35, 50, 40]
final array : [20, 35, 50, 40]
java.util.PriorityQueue shows: [20, 35, 50, 40]