MCPcopy
hub / github.com/kunal-kushwaha/DSA-Bootcamp-Java / downheap

Method downheap

lectures/27-huffman-coding/code/Heap.java:48–68  ·  view source on GitHub ↗
(int index)

Source from the content-addressed store, hash-verified

46 }
47
48 private void downheap(int index) {
49
50 int min = index;
51 int left = left(index);
52 int right = right(index);
53
54 // check is left < min
55 if(left < list.size() && list.get(min).compareTo(list.get(left)) > 0){
56 min = left;
57 }
58 // check if right < min
59 if(right < list.size() && list.get(min).compareTo(list.get(right)) > 0){
60 min = right;
61 }
62
63 if(min != index){
64 swap(min, index);
65
66 downheap(min);
67 }
68 }
69
70 private void swap(int first, int second) {
71 T temp = list.get(first);

Callers 1

removeMethod · 0.95

Calls 6

leftMethod · 0.95
rightMethod · 0.95
swapMethod · 0.95
sizeMethod · 0.45
compareToMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected