lecture3b - Lecture3:PointerbasedListADT...

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

View Full Document Right Arrow Icon
Lecture 3 : Pointer-based List ADT  Implementation Part ii. ECE 2574 Chao Huang Virginia Tech Fall 2009
Background image of page 1

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

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 2 Pointer-Based Linked Lists A node in a linked list is usually a  struct struct Node { int item Node *next; }; //end struct A node is dynamically allocated Node *p; p = new Node; A node
Background image of page 2
 C. Huang, Virginia Tech 3 Pointer-Based Linked Lists (cont’d) The head pointer points to the first node in a linked list The ending (last) node has a  NULL  pointer If head is  NULL , the linked list is empty A head pointer to a list
Background image of page 3

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

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 4 Saving and Restoring a Linked List Use an external file to preserve the list between runs Do not write pointers to a file, only data » Dynamical memory allocation Recreate the list from the file by placing each item at the end of  the list » Use a tail pointer to facilitate adding nodes to the end of the  list » Treat the first insertion as a special case by setting the tail  to head
Background image of page 4
 C. Huang, Virginia Tech 5 Passing a Linked List to a Function A function with access to a linked list’s  head  pointer has  access to the entire list Pass the head pointer to a function as a reference  argument void linkedListInsert( , ListItemType newItem) A head pointer as a value argument
Background image of page 5

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

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 6 Processing Linked Lists Recursively Recursive strategy to display a list » Write the first node of the list
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/11/2010 for the course ECE 2574 taught by Professor Chuang during the Spring '08 term at Virginia Tech.

Page1 / 21

lecture3b - Lecture3:PointerbasedListADT...

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

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