This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cargar(diccionario, kkey, value): | |
if key in diccionario.keys(): | |
diccionario[kkey]+=value | |
else: | |
diccionario[kkey]=value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bubble_sort(char vector_desordenado[MAX_VECTOR], char vector_ordenado[MAX_VECTOR], int tope, bool ascendente){ | |
int j, i; | |
for(i = 0; i < tope; i++){ | |
for(j = 0; j < tope-1; j++){ | |
if(ascendente){ | |
if(vector_desordenado[j] > vector_desordenado[j+1]){ | |
char aux = vector_desordenado[j]; | |
vector_desordenado[j] = vector_desordenado[j+1]; | |
vector_desordenado[j+1] = aux; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A selection sort algorithm that sorts descendingly or ascendingly depending of the boolean parameter. | |
void selection_sort(char vector_desordenado[MAX_VECTOR], char vector_ordenado[MAX_VECTOR], int tope, bool ascendente){ | |
for(int i = 0, i < tope, i++) | |
vector_ordenado[i] = vector_desordenado[i]; | |
for (int i = 0; i < tope; i++){ | |
int pos_min = i; | |
for (int j = i + 1; j < tope; j++){ | |
if (ascendente){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void insertion_sort(char vector_desordenado[MAX_VECTOR], char vector_ordenado[MAX_VECTOR], int tope, bool ascendente){ | |
int i, j; | |
for(i = 0; i < tope; i++) | |
vector_ordenado[i] = vector_desordenado[i]; | |
for(i = 0; i < tope; i++){ | |
int elemento_actual = vector_ordenado[i]; | |
j = i-1; | |
if(ascendente){ | |
while (j >= 0 && elemento_actual < vector_ordenado[j]){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def busqueda_lineal(lista, item): | |
largo=len(lista) | |
encontrado = False | |
i = 0 | |
while i < largo and encontrado == False: | |
if lista[i]==item: | |
posicion =i | |
encontrado = True | |
i+=1 | |
return posicion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def busqueda_binaria(lista, item): | |
largo = len(lista) | |
min = 0 | |
max =largo | |
posicion = None | |
while (min <= max and posicion == None): | |
medio = (min+max)//2 | |
if lista[medio] == item: | |
posicion = medio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
archivo = open(RUTA) | |
except FileNotFoundError: | |
archivo = open(RUTA, “w”) | |
archivo.close() | |
archivo = open(RUTA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
archivo = open(RUTA) | |
linea = archivo.readline() | |
while(linea != “”): | |
print(linea, end = “”) | |
linea = archivo.readline() | |
archivo.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def procesar_linea_csv(linea): | |
nombre, apellido, edad = linea.rstrip('\n').split(',') | |
return nombre, apellido, edad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
OlderNewer