We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
first, check if the head is null (means that its start with emapty list) then the first if condition will handle that
second, mantain head object by assigning its references to current then iterate over the current while current.next still containing Node, when it found current.next == null, means that current is the last Node, then it assign the new Node to Current.next and return the head
with this way, we makesure that current would never be found as null
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a Node at the Tail of a Linked List
You are viewing a single comment's thread. Return to all comments →
first, check if the head is null (means that its start with emapty list) then the first if condition will handle that
second, mantain head object by assigning its references to current then iterate over the current while current.next still containing Node, when it found current.next == null, means that current is the last Node, then it assign the new Node to Current.next and return the head
with this way, we makesure that current would never be found as null