Advertisement
adaptingear

Nodo python

Sep 18th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. class Nodo:
  2. def __init__(self, nombre=None, cedula=None, sig=None):
  3. self.nombre = nombre
  4. self.cedula = cedula
  5. self.sig = sig
  6.  
  7. def __str__(self):
  8. return "%s %s" %(self.nombre, self.cedula)
  9.  
  10. class lSimples:
  11. def __init__(self):
  12. self.cabeza = None
  13. self.cola = None
  14.  
  15. def agregar(self, elemento):
  16. if self.cabeza == None:
  17. self.cabeza = elemento
  18.  
  19. if self.cola != None:
  20. self.cola.sig = elemento
  21.  
  22. self.cola = elemento
  23.  
  24. def listar(self):
  25. aux = self.cabeza
  26. while aux != None:
  27. print(aux)
  28. aux = aux.sig
  29.  
  30.  
  31. if __name__ == "__main__":
  32. ls = lSimples()
  33. while(True): #SWITCH DE PYTHON
  34. print("-----MENU----\n"+
  35. "1. Agregar\n"+
  36. "2. Mostrar Lista")
  37. num = input("Ingrese la opcion")
  38. if num == "1":
  39. nombre = input("Ingresse el nombre: ")
  40. cedula = input("Ingrese la cedula: ")
  41. nod = Nodo(nombre, cedula)
  42. ls.agregar(nod)
  43. elif num == "2":
  44. ls.listar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement