MCPcopy Create free account
hub / github.com/geekcomputers/Python / heapify

Method heapify

Sorting Algorithims/heapsort_linkedlist.py:23–40  ·  view source on GitHub ↗
(self, n, i)

Source from the content-addressed store, hash-verified

21 print("None")
22
23 def heapify(self, n, i):
24 largest = i
25 left = 2 * i + 1
26 right = 2 * i + 2
27
28 current = self.head
29 for _ in range(i):
30 current = current.next
31
32 if left < n and current.data < current.next.data:
33 largest = left
34
35 if right < n and current.data < current.next.data:
36 largest = right
37
38 if largest != i:
39 self.swap(i, largest)
40 self.heapify(n, largest)
41
42 def swap(self, i, j):
43 current_i = self.head

Callers 1

heap_sortMethod · 0.95

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected