the node box Links are implemented as references to a node stored in an

The node box links are implemented as references to a

This preview shows page 7 - 14 out of 35 pages.

the node "box" Links are implemented as references to a node stored in an instance variable of the node type Links are typically illustrated as arrows that point to the node to which they "link" 15-7
Image of page 7
A Node Class (Part 1 of 3) 15-8
Image of page 8
A Node Class (Part 2 of 3) 15-9
Image of page 9
A Node Class (Part 3 of 3) 15-10
Image of page 10
A Simple Linked List Class The first node, or start node in a linked list is called the head node The entire linked list can be traversed by starting at the head node and visiting each node exactly once There is typically a variable of the node type (e.g., head ) that contains a reference to the first node in the linked list However, it is not the head node, nor is it even a node It simply contains a reference to the head node 15-11
Image of page 11
A Simple Linked List Class A linked list object contains the variable head as an instance variable of the class A linked list object does not contain all the nodes in the linked list directly Rather, it uses the instance variable head to locate the head node of the list The head node and every node of the list contain a link instance variable that provides a reference to the next node in the list Therefore, once the head node can be reached, then every other node in the list can be reached 15-12
Image of page 12
An Empty List Is Indicated by null The head instance variable contains a reference to the first node in the linked list If the list is empty, this instance variable is set to null Note: This is tested using == , not the equals method
Image of page 13
Image of page 14

You've reached the end of your free preview.

Want to read all 35 pages?

  • Winter '12
  • Ghouti
  • Subroutine, Array data structure

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture