The storage structure of a linked list data structure

  • A linked list is a data structure that organize a list of identical objects into a chain:

    The programmer only have (direct) access to the variable head

The storage structure of a linked list data structure

  • The linked list is stored in memory as followed:

    Notice that a list object (a.k.a. a node) consists of a data portion and a link

The storage structure of a linked list data structure

  • The head variable contains the reference (= address) to the first list element:

    Therefore: we can use head to access the fields within the first list element

  • Comment:   sometimes the head variable is called first
    -- I will both variable names interchangeably

The storage structure of a linked list data structure

  • The link field in a first list element contains the reference to the 2nd list element:

    Therefore: we can use this link field to access the fields within the 2nd list element

The storage structure of a linked list data structure

  • The link field in a 2nd list element contains the reference to the 3rd list element:

    And so on....

The storage structure of a linked list data structure

  • The link field in a last list element contains the NULL reference:

    The NULL reference is just the address value 0 (which is not used to store variables)