Bläddra i källkod

Added comments to the code

Alex Ortiz 2 år sedan
förälder
incheckning
41bd4aea93
1 ändrade filer med 12 tillägg och 3 borttagningar
  1. 12
    3
      sorting.py

+ 12
- 3
sorting.py Visa fil

@@ -23,20 +23,29 @@ def quickSort(lista):
23 23
 
24 24
 def shellSort(lista):
25 25
 	#definan el algoritmo de ordenamiento shellsort
26
-	Size = len(lista)
27
-	Diff = Size/2
26
+	Size = len(lista) # Contains the complete size of the list
27
+	Diff = Size/2 # Contains the number of half of the list
28 28
 
29
+	# Does a insertion sort by ordering in base of the Diff.
29 30
 	while Diff > 0:
31
+		# Begins a loop to sort the elements added to sorted array.
30 32
 		for i in range(Diff, Size):
33
+			# Saves the element sorted in a temporary variable
31 34
 			Tmp = lista[i]
32
-			j = i
35
+			j = i # Shifts the location of the elements
36
+			# Looks for the locations
33 37
 			while j >= Diff and lista[j - Diff] > Tmp:
38
+				# Gives the new element to the location
34 39
 				lista[j] = lista[j - Diff]
40
+				# The size of the array is ajusted
35 41
 				j -= Diff
42
+			# Puts the Tmp variable in is correct location
36 43
 			lista[j] = Tmp
44
+		# Reduces again the list
37 45
 		Diff /= 2
38 46
 
39 47
 	return lista
48
+	# Code was taken from GeeksforGeeks
40 49
 
41 50
 maxValor=1000 	#define el valor maximo de los elementos de la lista
42 51
 largoLista=1000 #define el largo de las listas a ordenar