Browse Source

Merge branch 'ShellSort' into sortingFinal

Merge ShellSort
Alex Ortiz 2 years ago
parent
commit
213c5676e6
1 changed files with 22 additions and 0 deletions
  1. 22
    0
      sorting.py

+ 22
- 0
sorting.py View File

72
 
72
 
73
 def shellSort(lista):
73
 def shellSort(lista):
74
 	#definan el algoritmo de ordenamiento shellsort
74
 	#definan el algoritmo de ordenamiento shellsort
75
+	Size = len(lista) # Contains the complete size of the list
76
+	Diff = Size/2 # Contains the number of half of the list
77
+
78
+	# Does a insertion sort by ordering in base of the Diff.
79
+	while Diff > 0:
80
+		# Begins a loop to sort the elements added to sorted array.
81
+		for i in range(Diff, Size):
82
+			# Saves the element sorted in a temporary variable
83
+			Tmp = lista[i]
84
+			j = i # Shifts the location of the elements
85
+			# Looks for the locations
86
+			while j >= Diff and lista[j - Diff] > Tmp:
87
+				# Gives the new element to the location
88
+				lista[j] = lista[j - Diff]
89
+				# The size of the array is ajusted
90
+				j -= Diff
91
+			# Puts the Tmp variable in is correct location
92
+			lista[j] = Tmp
93
+		# Reduces again the list
94
+		Diff /= 2
95
+
75
 	return lista
96
 	return lista
97
+	# Code was taken from GeeksforGeeks
76
 
98
 
77
 maxValor=1000 	#define el valor maximo de los elementos de la lista
99
 maxValor=1000 	#define el valor maximo de los elementos de la lista
78
 largoLista=1000 #define el largo de las listas a ordenar
100
 largoLista=1000 #define el largo de las listas a ordenar