4 Commit

Autore SHA1 Messaggio Data
  luislopez66 808a44fb81 Modified heap.py 2 anni fa
  luislopez66 b5bb1d8696 Modified heap.py and sorting.py 2 anni fa
  luislopez66 832ea0d1ac Modified heap.py and sorting.py 2 anni fa
  luislopez66 936700e246 Proper changes to sorting.py 2 anni fa
3 ha cambiato i file con 38 aggiunte e 17 eliminazioni
  1. BIN
      __pycache__/heap.cpython-310.pyc
  2. 17
    17
      heap.py
  3. 21
    0
      sorting.py

BIN
__pycache__/heap.cpython-310.pyc Vedi File


+ 17
- 17
heap.py Vedi File

@@ -12,27 +12,27 @@
12 12
 # i. Also, n is the size of a heap and arr is array.
13 13
 
14 14
 def heapify(lista, n, i):
15
-	largest = i # Initialize largest as root
16
-	l = 2 * i + 1 # left = 2*i + 1
17
-	r = 2 * i + 2 # right = 2*i + 2
15
+		# largest is root for now
16
+		largest = i
18 17
 
19
-	# See if left child of root exists and is
20
-	# greater than root
18
+		# left child of root
19
+		left = 2 * i + 1
21 20
 
22
-	if l < n and lista[i] < lista[l]:
23
-		largest = l
21
+		# right child of root
22
+		right = 2 * i + 2
24 23
 
25
-	# See if right child of root exists and is
26
-	# greater than root
24
+		# Checks if root has a left child and is greater
25
+		# than root
26
+		if l < n and lista[i] < lista[l] :
27
+			largest = l
27 28
 
28
-	if r < n and lista[largest] < lista[r]:
29
-		largest = r
29
+		# Checks if root has a right child and is greater
30
+		# than root
31
+		if r < n and lista[largest] < lista[r]:
32
+			largest = r
30 33
 
31
-	# Change root, if needed
32
-
33
-	if largest != i:
34
-		(lista[i], lista[largest]) = (lista[largest], lista[i]) # swap
35
-
36
-		# Heapify the root.
34
+		# If necessary, this changes root by swapping va-
35
+		# lues
36
+		lista[i], lista[largest] = lista[largest], lista[i]
37 37
 
38 38
 		heapify(lista, n, largest)

+ 21
- 0
sorting.py Vedi File

@@ -6,13 +6,20 @@ La variable largoLista define el largo de las listas a ordenar
6 6
 La variable veces define las veces que se va a hacer el ordenamiento
7 7
 La variable veces define las veces que se va a hacer el ordenamiento
8 8
 Al final se imprimen los promedios de cada algortimo
9
+<<<<<<< HEAD
9 10
 '''
10 11
 
12
+=======
13
+"""
14
+>>>>>>> sortingHeap
11 15
 import time
12 16
 from random import randint
13 17
 
14 18
 import heap
19
+<<<<<<< HEAD
15 20
 from merge import merge
21
+=======
22
+>>>>>>> sortingHeap
16 23
 
17 24
 # Python program for implementation of MergeSort
18 25
 
@@ -21,6 +28,7 @@ from merge import merge
21 28
 # Second subarray is arr[m+1..r]
22 29
 
23 30
 def mergeSort(lista, l, r):
31
+<<<<<<< HEAD
24 32
 	if l < r:
25 33
       # Same as (l+r)//2, but avoids overflow for
26 34
       # large l and h
@@ -39,6 +47,10 @@ def mergeSort(lista, l, r):
39 47
 '''
40 48
 
41 49
 # Python program for implementation of heap Sort (Part II)
50
+=======
51
+	# definan el algoritmo de ordenamiento mergesort
52
+	return lista
53
+>>>>>>> sortingHeap
42 54
 
43 55
 def heapSort(lista):
44 56
 	# Se busca el tamaño de la lista
@@ -52,6 +64,7 @@ def heapSort(lista):
52 64
 	h1 = (n // 2) - 1
53 65
 	for i in range(h1, -1, -1):
54 66
 		heap.heapify(lista, n, i)
67
+<<<<<<< HEAD
55 68
   
56 69
 	# Se extrae los elementos uno a uno
57 70
 	h2 = n - 1
@@ -60,6 +73,14 @@ def heapSort(lista):
60 73
 		lista[i], lista[0] = lista[0], lista[i]
61 74
 		heap.heapify(lista, 0, i)
62 75
   
76
+=======
77
+
78
+	h2 = n - 1
79
+	for i in range(h2, 0, -1):
80
+		lista[i], lista[0] = lista[0], lista[i]
81
+		heap.heapify(lista, 0, i)
82
+
83
+>>>>>>> sortingHeap
63 84
 	return lista
64 85
 
65 86
 def quickSort(lista):