DEPRECATED-data-structures icon indicating copy to clipboard operation
DEPRECATED-data-structures copied to clipboard

I don't know if this comment is the proper way to ask a question, but here it goes: shouldn't we update (head.prev).next to the new Node?

Open daniel-rios opened this issue 6 years ago • 5 comments

https://github.com/williamfiset/data-structures/blob/068c10624abab4568433f047fd7be3f24fb40d2a/com/williamfiset/datastructures/linkedlist/DoublyLinkedList.java#L80

daniel-rios avatar Sep 20 '19 21:09 daniel-rios

Yes, something seems to be missing? Haven't touched this code in a while. What I think should happen is that the current head's prev pointer should point to the new node, and the new node's next pointer should point to the current head. Then update the head pointer to be the new node. I'm surprised tests haven't caught this.

If you're up for it, can you update the code with the proper functionality and add test(s)? Also, FYI this repo was moved to the Algorithms repository so the current file to edit would be:

https://github.com/williamfiset/algorithms/blob/master/com/williamfiset/algorithms/datastructures/linkedlist/DoublyLinkedList.java

and the tests are at:

https://github.com/williamfiset/Algorithms/blob/master/javatests/com/williamfiset/algorithms/datastructures/linkedlist/LinkedListTest.java

williamfiset avatar Sep 21 '19 03:09 williamfiset

@williamfiset , What is the status of this issue? I can update and test it out if you want.

iamjoross avatar Nov 19 '19 07:11 iamjoross

I also got the impression that is something wrong at the first look. After taking a closer, everything seems to be correct.

Please check the previous line of code (line 79) and the constructor parameters of the new node.

For a reference:

      head.prev = new Node<T>(elem, null, **head**);
      head = head.prev;

skill-bit avatar Jan 09 '21 02:01 skill-bit

@williamfiset
What is the status of this issue? I can update

prashantkumar-cmd avatar Mar 17 '21 21:03 prashantkumar-cmd

As @skill-bit mentioned in above comment, there doesn't seem any issue with the current implementation.

It seems that this can be closed as 'Invalid'. @williamfiset, what do you think?

virallalakia avatar Mar 18 '21 02:03 virallalakia