The basic traversal pattern uses a single pointer: current = head while current != null: process(current.val) current = current.next This pattern has two critical details.
First, check current != null before accessing current.val or current.next. Accessing fields of null crashes your program.
Second, save current.next before modifying the node if you plan to change pointers. Once you overwrite current.next, you lose access to the rest of the list.
Time complexity is . Space complexity is since you only use one pointer regardless of list size. Time: . Space: .