On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote:
I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse.


I think the problem is here:

void popFront() { head = head.next; if (head !is null) head.prev = null; } void popBack() { tail = tail.prev; if (tail !is null) tail.next = null; }

Head and tail will point to the same nodes and you are setting the head.prev to null. Which would make the tail.prev null when iterating it backwards. Similarly if you started iterating it backwards and then iterating it forward it would not work.



Reply via email to