Преглед изворни кода

Delete 'heap.py'

removing from the project branch
orlando.medina4 пре 2 година
родитељ
комит
37e6ba371e
1 измењених фајлова са 0 додато и 38 уклоњено
  1. 0
    38
      heap.py

+ 0
- 38
heap.py Прегледај датотеку

@@ -1,38 +0,0 @@
1
-''' Luis Andrés López Mañán
2
-    Program written by hand as a draft on 09/19/2022
3
-    Credit goes to GeeksForGeeks
4
-    Link: https://www.geeksforgeeks.org/python-program-for-heap-sort/
5
-    Last access on 09/19/2022
6
-    Program wrriten and edited on 10/10/2022
7
-'''
8
-
9
-# This function heapifies a subtree rooted at an index
10
-# i. Also, n is the size of a heap and arr is array.
11
-
12
-def heapify(lista, n, i):
13
-        # largest is root for now
14
-		largest = i
15
-
16
-		# left child of root
17
-		l = 2 * i + 1
18
-
19
-		# right child of root
20
-		r = 2 * i + 2
21
-
22
-		# Checks if root has a left child and is greater
23
-		# than root
24
-		if l < n and lista[i] < lista[l] :
25
-			largest = l
26
-
27
-		# Checks if root has a right child and is greater
28
-		# than root
29
-		if r < n and lista[largest] < lista[r]:
30
-			largest = r
31
-
32
-		# If necessary, this changes root by swapping va-
33
-		# lues
34
-        if largest != i:
35
-            lista[i], lista[largest] = lista[largest], lista[i]
36
-
37
-		# This heapifies the root repeatedly
38
-		heapify(lista, n, largest)