Browse Source

merge Cynthia-Quicksort

cynthiarivera15 2 years ago
parent
commit
09a7ef7a64
1 changed files with 25 additions and 1 deletions
  1. 25
    1
      sorting.py

+ 25
- 1
sorting.py View File

@@ -59,7 +59,31 @@ def heapSort(lista):
59 59
 
60 60
 def quickSort(lista):
61 61
 	#definan el algoritmo de ordenamiento quicksort
62
-	return lista
62
+	if(len(lista) != 0):
63
+    		if(len(lista) == 1):
64
+      			return lista
65
+
66
+    		else:
67
+      			p = lista[0]
68
+
69
+      			for i in lista[1:]:
70
+        			if(p > i):
71
+          				x = i
72
+          				del lista[lista.index(i)]
73
+          				lista.insert(lista.index(p), x)
74
+          				print(lista)
75
+ 
76
+      			l = quickSort(lista[ :lista.index(p)])
77
+      			m = quickSort(lista[lista.index(p) + 1:])
78
+
79
+      			if(m != None and l != None):
80
+        			return l + lista[lista.index(p):lista.index(p) + 1] + m
81
+
82
+      			elif(m == None):
83
+        			return l + lista[lista.index(p):lista.index(p) + 1]
84
+
85
+      			elif(l == None):
86
+        			return lista[lista.index(p):lista.index(p) + 1] + m
63 87
 
64 88
 # inplace
65 89
 # complexity: O(N^2)