Skip to content
Advertisement

Did i correctly implement the recursive add function? My front node is remaining null

I am supposed to implement a recursive linked list, but after writing the code and debugging, it seems that my front node is remaining unchanged (it is staying at null). Any help will be appreciated.

JavaScript

Advertisement

Answer

According to your add method, you try to append the new node from the front-node. In your recursion if you check for node being null, this can only happen if front is not set. You try to set node = newNode, but because java is always pass-by-value the reference to front is never set.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement