• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

446
Vistas
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 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda