Skip to main content
ICT
Lesson AB29 - Linked List
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

I. Doubly-Linked Lists page 11 of 16

  1. The node of a doubly-linked list will contain the information field and two reference fields. One reference will refer to a previous node while the other reference will refer to the next node in the list.

  2. The following class definitions will be used:

    public class DListNode{
      private Object value;
      private DListNode next;
      private DListNode previous;

      // Constructor:
      public DListNode(Object initValue,
                       DListNode initNext,
                       DListNode initPrevious){

        value = initValue;
        next = initNext;
        previous = initPrevious;
      }

      public Object getValue(){
        return value;
      }

      public DListNode getNext(){
        return next;
      }

      public DListNode getPrevious(){
        return previous;
      }

      public void setValue(Object theNewValue){
        value = theNewValue;
      }

      public void setNext(DListNode theNewNext){
        next = theNewNext;
      }

      public void setPrevioust(DListNode theNewPrevious){
        previous = theNewPrevious;
      }
    }

  3. Figure 29-3 illustrates a doubly-linked list, of type DListNode containing Integer objects.


    Figure 29-3

  4. A null value must be placed at each end of the list to signify the end of the data structure. In the diagram, a null is indicated with the diagonal line.

  5. A doubly-linked list should have two external references to access the data structure. In the case above, first and last are the two entry points.

  6. A doubly-linked list can be traversed in either direction.

  7. Inserting values into an ordered doubly-linked list is a similar process to the algorithm used with a singly-linked list. However, the number of reference manipulations will double.

  8. The addition of a new node to a position between two existing nodes will require four reference hookups.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.