0

Trying to solve a problem with linked lists requiring the conversion of a singly linked list into doubly linked list. I'm definitely missing some syntax to do this but I haven't been able to figure out what I'm missing here.

The code is this.

var addPrev = function(head) {
    

    let copy = head;
    let prev = null;
    
    while(copy !== null){
        // The prev is just undefined console.log(copy, copy.prev);
        copy[prev]=prev
        prev=copy;
        copy=copy.next;
    };
   return head;
}
  • 1
    `copy[prev]` is not the same as `copy.prev`. You need the latter. Notice how you don't do `copy[next]` but `copy.next` for the same reason. – trincot Feb 09 '23 at 16:35
  • Ahhh, okay that makes some sense. I'll look into the dot vs [] notation more then. – user19568466 Feb 10 '23 at 18:34

0 Answers0