def modif_sw(arbol): file = abrir('starwars') busc = input('Ingrese nombre del personaje a modificar: ') val = busqueda_arbol(arbol, busc) if val is not None: print('1) Nombre') print('2) Altura') print('3) Peso') mod = input('Elija campo a modificar: ') sw = leer(file, pos) if mod == '1': nom = input('Ingrese el nuevo nombre: ') dato = Personaje(nom, sw.altura, sw.peso) modificar(file, pos, dato) sw = leer(file, pos) arbol = insertar_nodo(arbol, sw.nombre, pos) elif mod == '2': alt = int(input('Ingrese la nueva altura: ')) dato = Personaje(sw.nombre, alt, sw.peso) modificar(file, pos, dato) sw = leer(file, pos) arbol = insertar_nodo(arbol, sw.nombre, pos) elif mod == '3': peso = int(input('Ingrese el nuevo peso: ')) dato = Personaje(sw.nombre, sw.altura, peso) modificar(file, pos, dato) sw = leer(file, pos) arbol = insertar_nodo(arbol, sw.nombre, pos) else: print('ERROR') else: print('El personaje no existe') cerrar(file)
inorden_nombrank(arbol_nombre, file) cerrar(file) print() # c print('BARRIDO RANKING POR NIVEL') por_nivel(arbol_ranking) print() print('BARRIDO ESPECIE POR NIVEL') por_nivel(arbol_especie) print() # d print('Info de Luke Skywalker') print('NOMBRE | RANKING | ESPECIE | MAESTRO | COLOR DE SABLE | ORIGEN | AÑO DE NACIMIENTO | ALTURA') pos = busqueda_arbol(arbol_nombre, 'luke skywalker') if pos is not None: file = abrir('jedis') jedi = leer(file, pos.nrr) cerrar(file) print(jedi) print() print('Info de Yoda') print('NOMBRE | RANKING | ESPECIE | MAESTRO | COLOR DE SABLE | ORIGEN | AÑO DE NACIMIENTO | ALTURA') pos = busqueda_arbol(arbol_nombre, 'yoda') if pos is not None: file = abrir('jedis') jedi = leer(file, pos.nrr) cerrar(file) print(jedi)
arbol_autores = None # a b y c pos = 0 while pos < len(file): libro = leer(file, pos) print(libro.isbn, libro.cant, libro.titulo) arbol_isbn = insertar_nodo(arbol_isbn, libro.isbn, pos) arbol_titulo = insertar_nodo(arbol_titulo, libro.titulo, pos) for autor in libro.autores.split(';'): arbol_autores = insertar_nodo(arbol_autores, autor, pos) pos += 1 cerrar(file) print('') pos = busqueda_arbol(arbol_isbn, '567') if pos is not None: file = abrir('libros') libro = leer(file, pos.nrr) cerrar(file) print(libro.isbn, libro.cant, libro.titulo, libro.autores) print() file = abrir('libros') busqueda_proximidad_archivo(arbol_titulo, 'p', file) cerrar(file) print() file = abrir('libros') busqueda_archivo(arbol_titulo, 229, file) cerrar(file)
print('Barrido inorden') inorden(arbol) print() print('Barrido preorden') preorden(arbol) print() print('Barrido postorden') postorden(arbol) print() print('Barrido por nivel') por_nivel(arbol) print() # b buscado = int(input('Ingrese valor a buscar: ')) pos = busqueda_arbol(arbol, buscado) if pos is not None: print('El numero se encuentra en el arbol') else: print('El numero no existe') print() # c eliminado = int(input('Ingrese valor a eliminar: ')) pos = busqueda_arbol(arbol, eliminado) if pos is not None: arbol, eliminado = eliminar_nodo(arbol, eliminado) print('Se elimino:', eliminado) else: print('El numero no existe') print()
from TDA_ArbolBin_AVL import insertar_nodo, busqueda_arbol, por_nivel, hijo_der, hijo_izq from random import randint print('EJERCICIO 4') print() arbol = None for i in range(0, 10): arbol = insertar_nodo(arbol, randint(0, 100)) print('Barrido por nivel') por_nivel(arbol) print() buscado = int(input('Ingrese valor a buscar: ')) pos = busqueda_arbol(arbol, buscado) if pos is not None: print('hijo izquierdo') hijo_izq(arbol) print('hijo derecho') hijo_der(arbol) else: print('El numero no existe') print()