Browse Source

Added comments to the code

Alex Ortiz 2 years ago
parent
commit
41bd4aea93
1 changed files with 12 additions and 3 deletions
  1. 12
    3
      sorting.py

+ 12
- 3
sorting.py View File

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