Browse Source

Quicksort Algorithm

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

+ 25
- 1
sorting.py View File

@@ -20,7 +20,31 @@ def heapSort(lista):
20 20
 
21 21
 def quickSort(lista):
22 22
 	#definan el algoritmo de ordenamiento quicksort
23
-	return lista
23
+	if(len(lista) != 0):
24
+    		if(len(lista) == 1):
25
+      			return lista
26
+
27
+    		else:
28
+      			p = lista[0]
29
+
30
+      			for i in lista[1:]:
31
+        			if(p > i):
32
+          				x = i
33
+          				del lista[lista.index(i)]
34
+          				lista.insert(lista.index(p), x)
35
+          				print(lista)
36
+ 
37
+      			l = quickSort(lista[ :lista.index(p)])
38
+      			m = quickSort(lista[lista.index(p) + 1:])
39
+
40
+      			if(m != None and l != None):
41
+        			return l + lista[lista.index(p):lista.index(p) + 1] + m
42
+
43
+      			elif(m == None):
44
+        			return l + lista[lista.index(p):lista.index(p) + 1]
45
+
46
+      			elif(l == None):
47
+        			return lista[lista.index(p):lista.index(p) + 1] + m
24 48
 
25 49
 def shellSort(lista):
26 50
 	#definan el algoritmo de ordenamiento shellsort