MCPcopy
hub / github.com/gyoogle/tech-interview-for-developer / add

Method add

Algorithm/code/Heap.java:12–21  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

10 }
11
12 static void add(int n) {
13 arr[++heapSize] = n;
14
15 for (int i = heapSize; i > 1; i/=2) {
16 if(arr[i] < arr[i/2]) {
17 swap(i/2, i);
18 }
19 else break;
20 }
21 }
22 static int remove(int[] arr) {
23 if(heapSize == 0) return 0;
24

Callers 4

maxHeapMethod · 0.80
insertMethod · 0.80
minHeapMethod · 0.80
insertMethod · 0.80

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected