day20sup - COP 3503 Computer Science II CLASS NOTES - DAY...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CLASS NOTES - DAY #20 Supplement Although the concept of linking is common to all linked lists, a number of other issues can affect the implementation of a linked list in different fashions. Many of the design considerations that we will mention can be applied to virtually any linked list. Depending upon the application at hand, one or more of these implementations will be an appropriate solution. Some of these design issues are discussed in the sections that follow. Header Object: Should the list have a special node that maintains the reference to the first actual node in the list? If this special node is used it is typically called a header node The advantage of this technique is that there is always a node which “represents” the list. Operations on the list must go “through” this header node in order to gain access to the list itself. If no header node is used, then the first node of the actual list must “represent” the list. This implies that an empty list is denoted by null . Another, more subtle advantage of the header node will be illustrated when we develop insert and delete methods . A simple explanation will suffice for now: the header node will prevent special case insertion and deletion operations from occurring and will thus streamline the code for these methods. A disadvantage of the header node is that the list will contain a node which is not really a part of the list. Sometimes however, this header node can be used for storing useful information about the remainder of the list, such as the number of nodes currently in the list, etc. . List Termination: How should the list be terminated? One technique, which is very commonly used, is to have the reference field (the pointer) in the last node of the list refer to the special value null . A completely different technique, which has certain advantages, is to use a sentinel or special value in the last node of the list (and typically leave the last reference field undefined). As with the header node, the sentinel can be used to eliminate special cases for inserting and deleting within the linked list. This will be made clearer when we are actually looking at some of the linked list implementations. Single, Double, or Multiple Links: Single links (a singly linked list), permit the list to be traversed (walked) in only one direction. It is sometimes useful to be able to traverse the list in either a forward or backward direction and double links will be necessary. Double links however, will require more care on the programmers part to ensure that insertions and deletions to the list are properly handled. For more complex linking arrangements, multiple links may “enter” or “leave” a given node and care must be used by the programmer to ensure that the proper link is followed for a given situation. Day 20 Supplement -
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2009 for the course COP 3503c taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 6

day20sup - COP 3503 Computer Science II CLASS NOTES - DAY...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online