Skip to content

Circular linked list if statement evaluation #5

@diegocasmo

Description

@diegocasmo

I was wondering if anyone could explain to me why in the circular linked list example, on the insert method, why is it necessary to check if current.next is null. When exactly could node.next be null, if the tail of the linked list always keeps a reference to head?

if (node.next === null){ //update in case last element
  node.next = head;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions