import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){if(index <0|| index >=this.length){// index fuera de rangoreturnnull;}let nodeCurrent =this.head;let i =0;while(i!=index){ nodeCurrent = nodeCurrent.next; i++;}return nodeCurrent.value;}insertAt(index, value){if(index <0|| index >this.length-1){returnnull;}if(index ==0){//si el indice es 0 se inserta al principiothis.prepend(value);returnthis;}if(index ==this.length){//si el indice es igual a length, se inserta al finalthis.append(value);returnthis;}if(index >0&& index <this.length-1){//si el indice está en el medioconst newNode =newNode(value);const nodoPrev =this.nodeSearch(index -1)//buscamos al nodo previo newNode.next= nodoPrev.next//newNodo apunta al Nodo Posterior nodoPrev.next= newNode;//nodo previo apunta al nuevo nodothis.length++;returnthis;}}toArray(){let values =[];let pointer =this.head;for(let i =0; i <this.length; i++){ values.push(pointer.value); pointer = pointer.next;}return values;}removeAt(index){if(index <0|| index >this.length-1){returnnull;}if(index ==0){//se elimina el primer nodothis.head=this.head.next;this.length--;returnthis;}if(index ==this.length-1){//se elimina el último nodoconst nodoPrev =this.nodeSearch(index -1);this.tail= nodoPrev; nodoPrev.next=null;this.length--;returnthis;}if(index >0&& index <this.length-1){//si el indice está al medioconst nodoPrev =this.nodeSearch(index -1)//buscamos al nodo previoconst nodoPost =this.nodeSearch(index +1)//buscamos al nodo posterior nodoPrev.next= nodoPost;//el nodo previo ahora apunta al nodo posteriorthis.length--;returnthis;}}nodeSearch(index){let pointerSearch =this.head;let i =0;if(index <0|| index >=this.length){thrownewError("El índice esta fuera de rango");}while(i != index && pointerSearch.next!=null){ pointerSearch = pointerSearch.next; i++;}return pointerSearch;}}
Hola, en el método insertAt(index, value) tienes la condición de que 'index' tiene que ser mayor al tamaño de la lista -1:
if(index <0|| index >this.length-1){returnnull;}
Pero más abajo, se tiene también:
if(index ==this.length){//si el indice es igual a length, se inserta al finalthis.append(value);returnthis;}
.
Por lo que 'index' nunca va a ser igual a 'this.length', debido a la primera condición. Por ende no se podrá insertar un nodo al final de la lista.
.
Podrías resolverlo modificando la primera condición:
.
if(index <0|| index >this.length){returnnull;}
.
Pero si lo haces el playground marca error 😅, porque no permite un 'index' fuera de rango, que puede ser el caso de un 'index' igual al tamaño de la lista.
.
.
.
.
.
.
classLinkedListRechargedextendsLinkedList{get(index){if(!this.head){returnnull;}let counter =0;let currentNode =this.head;while(counter != index){if(currentNode.next===null){returnnull;} currentNode = currentNode.next; counter++;}return currentNode.value;}insertAt(index, value){if(index <0|| index >this.length)returnnull;const newNode =newNode(value);let currentNode =this.head;let previousNode =null;for(let i =0; i < index; i++){ previousNode = currentNode; currentNode = currentNode.next;}if(!previousNode){this.prepend(value);}elseif(!currentNode){this.append(value);}else{ newNode.next= currentNode; previousNode.next= newNode;this.length++;}returnnull;}toArray(){let values =[];let currentNode =this.head;while(currentNode){ values.push(currentNode.value); currentNode = currentNode.next;}return values;}removeAt(index){const value =this.get(index); index <0|| index >=this.length?null:this.delete(value);return value;}}
Al parecer tengo un error en el método insertAt() pero cuando corro mi código en un editor funciona correctamente.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
get(index){if(index >this.length-1){returnnull}let currentNode =this.headfor(let i =0; i !== index; i++){ currentNode = currentNode.next//Lo que hay que tener en cuenta }return currentNode.value}insertAt(index, value){let currentNode =this.headif(index >=this.length|| index <0){returnnull}elseif(index ===0){this.prepend(value)}elseif(index ===this.length-1){this.append(value)}else{let i =0while(i < index){ currentNode = currentNode.next i++} currentNode.value= value// Remplazothis.length++}}toArray(){let currentNode =this.headlet valoresEstructuraLineal =[]for(let i =0; i !==this.length; i++){ valoresEstructuraLineal.push(currentNode.value) currentNode = currentNode.next}return valoresEstructuraLineal
}removeAt(index){let nodeDelete =this.headfor(let i =0; i !== index; i++){ nodeDelete = nodeDelete.next//Lo que hay que tener en cuenta }returnthis.delete(nodeDelete.value)}}
Hola la solución, con ayuda de los comnentarios.
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){if(index <0|| index >=this.length){returnnull;}let currentNode =this.head;for(let i =0; i < index; i++){ currentNode = currentNode.next;}return currentNode.value;}insertAt(index, value){if(index <0|| index >=this.length){returnnull;}const newNode =newNode(value);if(index ===0){ newNode.next=this.head;this.head= newNode;if(!this.tail){this.tail= newNode;}this.length++;return newNode;}let currentNode =this.head;for(let i =0; i < index -1; i++){ currentNode = currentNode.next;} newNode.next= currentNode.next; currentNode.next= newNode;if(!newNode.next){this.tail= newNode;}this.length++;return newNode;}toArray(){const result =[];let currentNode =this.head;while(currentNode){ result.push(currentNode.value); currentNode = currentNode.next;}return result;}removeAt(index){if(index <0|| index >=this.length){returnnull;}let deletedNode =null;if(index ===0){ deletedNode =this.head;this.head=this.head.next;if(this.length===1){this.tail=null;}this.length--;return deletedNode.value;}let currentNode =this.head;for(let i =0; i < index -1; i++){ currentNode = currentNode.next;} deletedNode = currentNode.next; currentNode.next= currentNode.next.next;if(!currentNode.next){this.tail= currentNode;}this.length--;return deletedNode.value;}}
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){// Tu código aquí 👈if(index <0|| index >=this.length)returnnull;let currentNode =this.head;for(let i =0; i <=this.length-1; i++){if(index === i)return currentNode.value; currentNode = currentNode.next;}}insertAt(index, value){// Tu código aquí 👈const newNode =newNode(value);if(index <0|| index >=this.length)returnnull;if(index ===0){this.prepend(value);return;}if(index ===this.length){this.append(value);return;}let currentNode =this.head;let prevNode;for(let i =0; i <=this.length-1; i++){if(index === i){ newNode.next= currentNode; prevNode.next= newNode;this.length++;return;} prevNode = currentNode; currentNode = currentNode.next;}}toArray(){// Tu código aquí 👈const nodes =[];let currentNode =this.head;for(let i =1; i <=this.length; i++){ nodes.push(currentNode.value);if(i <this.length) currentNode = currentNode.next;}return nodes;}removeAt(index){// Tu código aquí 👈if(index <0|| index >=this.length)returnnull;if(index ===0){this.delete(this.head.value);return;}let currentNode =this.head;let i =1;while(currentNode.next){if(index === i){let retValue = currentNode.next.value; currentNode.next= currentNode.next.next;this.length--;return retValue;} currentNode = currentNode.next; i++;}}}
💚Mi Solución💚
🛡️MURO ANTI-SPOILERS🛡️
!cats
🎯Nota
La mayoría de mi código esta comentado en algunas partes para comprender que se hace en cada bloque de código. Sin embargo, me gustaría puntualizar que en el método insertAt() las pruebas consideran un indice fuera de los límites el que sea igual a el length, en mi caso quise dejar mi código con el caso en el que es igual al length que en otras palabras es añadir a la cola.
Si requieren hacer pasar las pruebas solamente en el primer if de ese metodo es cambiar index > this.length por index >= this.length y eliminar el código del Caso2 (porque no se ocupa).
Sin duda alguna recorrer la SinglyLinkedList es fácil, pero lo dificil es insertar o remover los apuntadores a nodo siguiente. Recomiendo mucho hacer un dibujo con flechitas para que se observe como cambian los apuntadores.
👁️ Nota
En el método delete() proporcionado en clase no hay ningún problema al remover en medio o en cabeza. Sin embargo, al remover en cola el método si lo elimina efectivamente pero falta actualizar this.tail, solo sería agregar una validación para actualizarlo.
👾Código
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){if(index >=this.length|| index <0)returnnulllet actualNode =this.head;while(index >0){ actualNode = actualNode.next index--}return actualNode.value}insertAt(index, value){if(index >this.length|| index <0)returnnull//Index out of bounds//Caso1: Se añade en la cabezaif(index ==0){this.prepend(value)return}//Caso2: Se añade en la colaif(index ==this.length){this.append(value)return}//Caso3: Se añade en el mediolet actualNode =this.headwhile(index >1){ actualNode = actualNode.next index--}//El actualNode es un nodo antes de donde queremos insertarconst nodeToInsert =newNode(value)const nextOfNodeToInsert = actualNode.next actualNode.next= nodeToInsert
nodeToInsert.next= nextOfNodeToInsert
this.length++}toArray(){const array =[]let actualNode =this.headfor(let i =0; i <this.length; i++){ array.push(actualNode.value) actualNode=actualNode.next}return array
}removeAt(index){if(index >=this.length|| index <0)returnnull//Index out of boundslet value =null//Caso1: Se quiere eliminar la cabezaif(index ===0){ value =this.head.valuethis.head=this.head.nextif(--this.length===0)//Si eliminamos ya todothis.tail=nullreturn value
}//Caso2: Se quiere eliminar en medio o en cola//Obtenemos un nodo previo al que queremos eliminarlet actualPrevNode =this.head;while(index >1){ actualPrevNode = actualPrevNode.next index--} value = actualPrevNode.next.value//Hilamos al nodo siguiente del que queremos eliminar actualPrevNode.next= actualPrevNode.next.next//Caso3: En que el nodo que eliminamos fue la colaif(actualPrevNode.next===null)this.tail= actualPrevNode
this.length--return value
}}
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{getNodo(index){if(index <0|| index >=this.length)returnnull;let currentNodo =this.head;for(let i =0; i < index; i++){ currentNodo = currentNodo.next;}return currentNodo;}get(index){const nodo =this.getNodo(index);return nodo ? nodo.value:null;}insertAt(index, value){if(index <0|| index >=this.length)returnnull;if(index ===0){this.prepend(value);return;}if(index ===this.length-1){this.append(value);return;}const newNodo =newNode(value);const prevNodo =this.getNodo(index -1); newNodo.next= prevNodo.next; prevNodo.next= newNodo;this.length++;return;}toArray(){const values =[];let currentNodo =this.head;for(let i =0; i <this.length; i++){ values.push(currentNodo.value); currentNodo = currentNodo.next;}return values;}removeAt(index){if(index <0|| index >=this.length)returnnull;const value =this.get(index);this.delete(value);return value;}}
exportclassLinkedListRechargedextendsLinkedList{get(index){if(index <0|| index >=this.length){returnnull;}let current =this.head;for(let i =0; i < index; i++){ current = current.next;}return current.value;}insertAt(index, value){if(index <0|| index >=this.length){returnnull}const newNode =newNode(value)if(index ===0){ newNode.next=this.headthis.head= newNode
if(!this.tail){this.tail= newNode
}this.length++return newNode
}let currentNode =this.headfor(let i =0; i < index -1; i++){ currentNode = currentNode.next} newNode.next= currentNode.next currentNode.next= newNode
if(!newNode.next){this.tail= newNode
}this.length++return newNode
}toArray(){const arr =[];let current =this.head;while(current){ arr.push(current.value); current = current.next;}return arr;}removeAt(index){if(index <0|| index >=this.length){returnnull;}let removedValue;if(index ===0){ removedValue =this.head.value;this.head=this.head.next;}else{let current =this.head;for(let i =0; i < index -1; i++){ current = current.next;} removedValue = current.next.value; current.next= current.next.next;}this.length--;return removedValue;}}
Mi solución:
.
.
.
.
.
.
.
.
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){if(index >=this.length|| index <0){returnnull}let currentNode =this.headfor(let i =0; i < index; i++){ currentNode = currentNode.next}return currentNode.value}insertAt(index, value){if(index >=this.length|| index <0){console.log(null)returnnull}if(index ===0){this.prepend(value)return}if(index ==this.length-1){this.append(value)return}let currentNode =this.headlet nextNode = currentNode.nextfor(let i =0; i < index -1; i++){ currentNode = currentNode.next nextNode = currentNode.next}const newNode =newNode(value) currentNode.next= newNode
newNode.next= nextNode
this.length++}toArray(){let array =[]let currentNode =this.headfor(let i =0; i <this.length; i++){ array.push(currentNode.value) currentNode = currentNode.next}return array
}removeAt(index){const value =this.get(index)this.delete(value)return value
}}
Solución… 😄
.
Reto interesante, creo que el playground en el método 'insertAt' no permite insertar un nodo al final de la lista, porque el 'index' saldría fuera de rango.
.
Pero aún así adjunto la solución del playground y la solución que permite insertar un nodo al final de la lista utilizando el método 'insertAt' si lo quieren ver 😄.
.
.
Solución (no pasa la prueba del playground, pero se puede verificar en la pestaña 'Vista´ del mísmo) que permite agregar un nodo al final de la lista:
Mi solución:
Después de revisar otros algoritmos. Creo que mi propuesta es un poco más legible:
.
.
.
.
.
.
.
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){let currentNode =this.head;if(index>=0&&index <this.length){for(let i =0; i <this.length; i++){if(i !== index){ currentNode = currentNode.next}else{return currentNode.value}}}else{returnnull}}insertAt(index, value){let currentNode =this.head;const newNode =newNode(value)if(index>=0&&index <this.length){for(let i =0; i <this.length; i++){if(i !== index-1){if(currentNode.next) currentNode = currentNode.next}else{ newNode.next= currentNode.next currentNode.next=newNode
this.length++return}}}else{returnnull}}toArray(){constarrLinkedList=()=>{const array =[]let currentNode =this.head;for(let i =0; i <this.length; i++){ array.push(currentNode.value)if(currentNode.next) currentNode = currentNode.next}return array
}returnarrLinkedList()}removeAt(index){let currentNode =this.head;if(index>=0&&index <this.length){for(let i =0; i <this.length; i++){if(i !== index-1){if(currentNode.next) currentNode = currentNode.next}else{const removed = currentNode.next currentNode.next= currentNode.next.nextthis.length--return removed
}}}else{returnnull}}}
Solucion
Necesite revisarlo muchas veces antes de entender bien el funcionamiento de los LinkedLists.
+
+
+
+
+
+
+
+
+
+
classLinkedListRechargedextendsLinkedList{get(index){// Tu código aquí 👈if(index <0|| index >this.length)returnnull;let counter =0;let currentNode =this.head;while(currentNode){if(counter === index){return currentNode;} currentNode = currentNode.next; counter++;}}insertAt(index, value){// Tu código aquí 👈// Check for head and tail positionif(index <0|| index >=this.length)returnnull;// Create node// insert node at headif(index ===0)this.prepend(value);elseif(index ===this.length-1)this.append(value);else{const newNode =newNode(value);const prevNode =this.get(index -1); newNode.next= prevNode.next; prevNode.next= newNode;this.length++;return newNode;}}toArray(){// Tu código aquí 👈let arrayFromLinkedList =newArray(this.length);let currentNode =this.head;let i =0;while(currentNode){ arrayFromLinkedList[i]= currentNode.value; currentNode = currentNode.next; i++;}console.log(arrayFromLinkedList);return arrayFromLinkedList;}removeAt(index){// Tu código aquí 👈if(index <0|| index >=this.length)returnnull;if(index ===0|| index ===this.length-1){const deletedNode =this.get(index);this.delete(deletedNode.value);return deletedNode;}else{const prevNode =this.get(index -1);const removedNode = prevNode.next;const realocatedNode = removedNode.next; prevNode.next= realocatedNode;this.length--;return removedNode.value;}}}
Aquí mi solución:
.
.
.
.
.
.
.
.
.
.
.
.
classLinkedListRechargedextendsLinkedList{get(index){if(index <0&& index >this.length){returnnull;}if(!this.head){returnnull;}let ii =0;let currentNode =this.head;while(ii <=this.length){if(ii === index){return currentNode.value;}if(currentNode.next){ currentNode = currentNode.next; ii++}else{returnnull;}}}insertAt(index, value){if(index <0&& index >this.length){returnnull;}if(!this.head){returnnull;}let ii =0;let currentNode =this.head;let newNode;let antNode;while(ii <=this.length){if(ii ===(index -1)){ antNode = currentNode;}elseif(ii === index){ newNode =newNode(value); newNode.next= currentNode; antNode.next= newNode;if(ii ===0){this.head= newNode;}elseif(ii ===this.length){this.tail= newNode;}}if(currentNode.next){ currentNode = currentNode.next; ii++}else{returnnull;}}}toArray(){let newarray =[];if(!this.head){returnnull;}// Si el nodo a eliminar es el primer nodo en la lista// se recorre la lista buscando el nodo anterior al que se quiere eliminarlet currentNode =this.head;while(currentNode.next){ newarray.push(currentNode.value) currentNode = currentNode.next;} newarray.push(currentNode.value)return newarray;}removeAt(index){if(index <=0|| index >=this.length){returnnull;}if(!this.head){returnnull;}if(index ===0){this.head=this.head.next;this.length--;returnthis.length;}let ii =0;let antNode;let currentNode =this.head;while(ii <=this.length){if(ii ===(index -1)){ antNode = currentNode;}elseif(ii === index){if(currentNode.next){ antNode.next= currentNode.next}else{ antNode.next=null}this.length--if(ii ===this.length){this.tail= newNode;}returnthis.length;}if(currentNode.next){ currentNode = currentNode.next; ii++}}}}
,
,
,
,
,
,
,
,
,
,
,
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){if(index <0|| index >=this.length){returnnull;}let current =this.head;for(let i =0; i < index; i++){ current = current.next;}return current.value;}insertAt(index, value){if(index <0|| index >=this.length){returnnull;}const newNode =newNode(value);if(index ===0){ newNode.next=this.head;this.head= newNode;}else{let current =this.head;for(let i =0; i < index -1; i++){ current = current.next;} newNode.next= current.next; current.next= newNode;}this.length++;return newNode;}toArray(){const array =[];let current =this.head;while(current){ array.push(current.value); current = current.next;}return array;}removeAt(index){if(index <0|| index >=this.length){returnnull;}let removedNode;if(index ===0){ removedNode =this.head;this.head=this.head.next;}else{let current =this.head;for(let i =0; i < index -1; i++){ current = current.next;} removedNode = current.next; current.next= current.next.next;}this.length--;return removedNode.value;}}
Logre que mi solución quedara mas cortita que la solución :D
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
excercise.js
import{LinkedList}from"./SinglyLinkedList";import{Node}from"./Node";exportclassLinkedListRechargedextendsLinkedList{get(index){if(index <0|| index >=this.length){returnnull}let i =0;let currentNode =this.head;while(index !== i){ currentNode = currentNode.next; i++;}return currentNode.value;}insertAt(index, value){if(index <0|| index >=this.length){returnnull}if(index >=this.length){this.append(newNode);}const newNode =newNode(value);const firstPointer =this.getIndex(index -1);const holdingPointer = firstPointer.next; firstPointer.next= newNode; newNode.next= holdingPointer;this.length++;}toArray(){let currentNode =this.head;let i =0;let array =[];while(i <this.length){ array.push(currentNode.value); currentNode = currentNode.next; i++;}return array;}removeAt(index){if(index <0|| index >=this.length){returnnull}const firstPointer =this.getIndex(index -1);const holdingPointer =this.getIndex(index +1); firstPointer.next= holdingPointer;this.length--;returnthis;}getIndex(index){if(index <0|| index >=this.length){returnnull}let i =0;let currentNode =this.head;while(index !== i){ currentNode = currentNode.next; i++;}return currentNode;}}
🛡️🛡️🛡️Escudo anti spoilers🛡️🛡️🛡️
Agrega métodos a singly linked list
!Spoiler Shield
Decidí complicarme la vida y hacerlo con recursividad y closures 😂 a continuación mi solución explicada con comentarios casi en cada línea tratando de que sea lo mas entendible posible
Nunca pares de aprender 🦾
get(index)
get(index){// Si el index es < 0 o > length se levanta un errorif(index <0|| index >this.length-1){returnnull}// Variable para almacenar profundiad actuallet actual =this;// Funcion recursiva para subir capasfunctiongetValue(){// Si está en el head el actual es el primer nodoif(actual.head){ actual = actual.head;}// Si no está en el head diminuye el index y asigna al siguiente nodo como el actualelse{ index = index -1; actual = actual.next;}// En caso de que el index llegue a 0 se retorna el valor del nodoif(index ==0){return actual.value;}// Se vuelve a llamar la función dentro de la recurrenciareturngetValue();}// Se llama la funcion desde get(index)returngetValue();}
insertAt(index,value)
insertAt(index, value){// Si el index es < 0 o > length se levanta un errorif(index <0|| index >this.length-1){returnnull}// Variable para almacenar profundiad actuallet actual =this;// Se aumenta en 1 a la longitud de la listathis.length++;// Funcion recursiva para subir capasfunctionappendValue(){// Si está en el head el actual es el primer nodoif(actual.head){ actual = actual.head;}// Si no está en el head diminuye el index y asigna al siguiente nodo como el actualelse{ index = index -1; actual = actual.next;}// En caso de que el index llegue a 0 quiere decir que estamos en la posicion a insertarif(index ==0){// Se crea una nueva instancia de nodo con el valor a insertarlet oldNode =newNode(actual.value);// Se "COPIA" todo el contenido del nodo en el que estamos a el nodo anterior oldNode.next= actual.next;// Se reemplaza el nodo actual con el valor que llega por parametro actual.value= value;// Se reemplaza el siguiente nodo con el nodo creado actual.next= oldNode;// Se retorna el valor insertadoreturn value;}// Se vuelve a llamar la función dentro de la recurrenciareturnappendValue();}// Se llama la funcion desde insertAt(index, value)returnappendValue();}
toArray()
toArray(){// Variable para almacenar profundiad actual y array a retornarlet actual =this;const arr =[];// Funcion recursiva para subir capasfunctionpushToArray(){// Si está en el head el actual es el primer nodoif(actual.head){ actual = actual.head;}// Se actual.next es null quiere decir que es la ultima capa// Entonces se agrega el ultmo valor y se retorna el arregloif(actual.next==null){ arr.push(actual.value);return arr;}// Si no está en el head diminuye el index y asigna al siguiente nodo como el actualelse{ arr.push(actual.value); actual = actual.next;}// Se vuelve a llamar la función dentro de la recurrenciareturnpushToArray();}// Se llama la funcion desde toArray()returnpushToArray();}
removeAt(index)
removeAt(index){// Si el index es < 0 o > length se levanta un errorif(index <0|| index >this.length-1){returnnull}// Variable para almacenar profundiad actuallet actual =this;// Se disminuye en 1 a la longitud de la listathis.length--;// Funcion recursiva para subir capasfunctiondeleteValue(){// Si está en el head el actual es el primer nodoif(actual.head){ actual = actual.head;}// Si no está en el head diminuye el index y asigna al siguiente nodo como el actualelse{ index = index -1; actual = actual.next;}// En caso de que el index llegue a 0 quiere decir que estamos en la posicion a eliminarif(index ==0){// Se crea una nueva instancia de nodo excluyendo el valor a eliminarconst newNode =newNode(actual.next.value) newNode.next= actual.next.next actual.value= newNode.value actual.next= newNode.next// Se retorna el valor eliminadoreturn;}// Se vuelve a llamar la función dentro de la recurrenciareturndeleteValue();}// Se llama la funcion desde insertAt(index, value)returndeleteValue();}