Esempio n. 1
0
 def insertarElemento(self, posicion, componente):
     retorno = False
     mensajeError = 'Error: posicion ingresada fuera de rango, la lista tiene {} componentes'.format(
         self.__tope)
     if posicion == 0:
         self.agregarElementoInicio(componente)
         retorno = True
     else:
         if self.__comienzo == None:
             print(mensajeError)
         else:
             i = 0
             aux = self.__comienzo
             while i < posicion and aux != None:
                 anterior = aux
                 aux = aux.getSiguiente()
                 i += 1
             try:
                 assert i == posicion and aux != None, 'Error'
             except:
                 print(mensajeError)
             else:
                 nuevoNodo = Nodo(componente)
                 nuevoNodo.setSiguiente(aux)
                 anterior.setSiguiente(nuevoNodo)
                 self.__tope += 1
                 retorno = True
     return retorno
Esempio n. 2
0
 def agregarElementoFin(self, componente):
     retorno = False
     if self.__comienzo == None:
         self.agregarElementoInicio(componente)
         retorno = True
     else:
         aux = self.__comienzo
         siguiente = aux.getSiguiente()
         while siguiente != None:
             aux = siguiente
             siguiente = siguiente.getSiguiente()
         nuevoNodo = Nodo(componente)
         nuevoNodo.setSiguiente(None)
         aux.setSiguiente(nuevoNodo)
         self.__tope += 1
         retorno = True
     return retorno
 def insertarElemento(self, elemento, pos):
     band = False
     if (pos < -self.__tope) or (pos > self.__tope):
         if (pos == -1):
             band = True
         else:
             raise IndexError('list index out of range')
     else:
         band = True
     if band:
         nodo = Nodo(elemento)
         if self.__comienzo == None:  #Coleccion vacía
             self.__comienzo = nodo
             self.__actual = nodo
             self.__tope += 1
         else:
             if pos >= 0:
                 if pos == 0:  #Posicion positivo
                     nodo.setSiguiente(self.__comienzo)
                     self.__comienzo = nodo
                     self.__actual = nodo
                     self.__tope += 1
                 else:
                     ant = self.__comienzo
                     aux = ant.getSiguiente()
                     i = 0
                     while i < (pos - 1):
                         ant = aux
                         aux = aux.getSiguiente()
                         i += 1
                     nodo.setSiguiente(aux)
                     ant.setSiguiente(nodo)
                     self.__tope += 1
             else:  #Posicion negativa
                 if pos == -self.__tope:
                     nodo.setSiguiente(self.__comienzo)
                     self.__comienzo = nodo
                     self.__actual = nodo
                     self.__tope += 1
                 else:
                     ant = self.__comienzo
                     aux = ant.getSiguiente()
                     i = -self.__tope
                     while i < (pos - 1):
                         ant = aux
                         aux = aux.getSiguiente()
                         i += 1
                     nodo.setSiguiente(aux)
                     ant.setSiguiente(nodo)
                     self.__tope += 1
Esempio n. 4
0
 def agregarProfesor(self, profesor):
     nodo = Nodo(profesor)
     nodo.setSiguiente(self.__comienzo)
     self.__comienzo = nodo
     self.__actual = nodo
     self.__tope += 1
Esempio n. 5
0
 def agregarElementoInicio(self, componente):
     nuevoNodo = Nodo(componente)
     nuevoNodo.setSiguiente(self.__comienzo)
     self.__comienzo = nuevoNodo
     self.__tope += 1