Answer the question
In order to leave comments, you need to log in
Does anyone have a little cheat sheet on iterating over a linked list?
When should the while(list != null) and while(list.next != null) conditions be used ? In order to be confident in the condition at interviews.
Answer the question
In order to leave comments, you need to log in
When should the condition while(list != null) and while(list.next != null) be used?
The interview should be held, thinking with your head, and not remembering some crazy patterns. The purpose of fucking you with these lists is not to find out that you remember patterns, but to see how you "twist" the code in your head.
Usually
list.next == null means the current element (list) is the last one in the list
list == null - there is no list, possibly an error
Both options can be used in the same implementation in different situations.
In addition, there may be nuances and list.next == null in this particular implementation of the list is an error, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question