Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

623
Visualizações
Implement the addInPos method inside the prototype of LinkedList which should add an element in the indicated position

Implement the addInPos method inside the prototype of LinkedList which should add an element in the indicated position. Both data will be provided as a parameter (pos, values). Where "pos" will be the position in which the value "values" should be added.

In the event that the position in which the insertion is to be made is not valid (exceeds the size of the current list), it must return false. If the node was added correctly, return true. Clarification: the zero position corresponds to the head of the LinkedLis.

  • Example 1:

Assuming the current list is: Head --> [1] --> [2] --> [4]

list.addInPos(2, 3);

Now the list would be: Head --> [1] --> [2] --> [3] --> [4]

  • Example 2:

Assuming the list is empty: Head --> null.

list.addInPos(2, 3); --> Should return false since it is not possible to add at position 2 without first having position 0 and 1 loaded

LinkedList.prototype.addInPos = function (pos, values) {
    /* Your code here */
}
if(!this.head)
  {
    this.head = new Node(values);
    return;
  }

  // not empty find the place with getAt and insert
  let previo = this.getAt(pos - 1);
  let tmpNodo = new Node(values);
  tmpNodo.next = previo.next;
  previo.next = tmpNodo;
  return this.head;
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda