How to create a function that inserts at the bottom of the list (PYTHON ) using the signature : def inserts Fim(self, item)

Asked

Viewed 34 times

0

class Noh:
    def __init__(self, campo):
        self.campo = campo
        self.prox = None

    def getCampo(self): return self.campo

    def getProx(self): return self.prox

    def setCampo(self, nc): self.campo = nc

    def setProx(self, np): self.prox = np

class LL:

    def __init__(self): self.inicio = None

    def taVazia(self): return self.inicio is None

    def insereInicio(self, item):
        temp = Noh(item)
        temp.setProx(self.inicio)
        self.inicio = temp

    def tamanho(self):
        atual = self.inicio
        cont = 0
        while atual is not None:
            cont = cont + 1
            atual = atual.getProx()
        return cont

    def busca(self, item):
        atual = self.inicio
        encontrado = False
        while atual is not None and not encontrado:
            if atual.getCampo() is item:
                encontrado = True
            else:
                atual = atual.getProx()

        return encontrado

    def imprime(self):
        atual = self.inicio
        elementos = []
        while atual is not None:
            elementos.append(atual.campo)
            atual = atual.getProx()
        print(elementos)

    def remove(self, item):
        pass

1 answer

0

def insereFim(self, item):
    temp = Noh(item)
    if self.inicio is None:
        self.inicio = temp
        return
    fim = self.inicio
    while(fim.getProx()):
        fim = fim.getProx()
    fim.setProx(temp)
  • You could add to your answer details on its amendment to make it easier for the questioner to understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.