# Class 35: Lists, Concluded

Back to Project Discussion. On to Introduction to Linear Structures.

Held Monday, November 1, 1999

Overview

Today, we will conclude our discussion of lists by considering other issues in the design of linked lists.

Notes

• I won't be available for office hours today. Sorry.
• There's an interesting talk tomorrow at 4:30 by Vivek Venugopal and Jared Seaman on their summer research. I encourage you to attend.
• You cannot take CSC302 next semester. 302 as a 301 prereq.
• You shouldn't be able to take CSC364, which has a 211/213 prereq. However, we have decided to waive that prereq so that there is an avialable course.
• You should take MAT218 next semester (or MAT215, if you haven't done so already).
• Those of you taking MAT218 next semester might want to consider the 2-credit Games Theory special topics course being offered.

Contents

Handouts

Summary

## List Cursors

• Rather than providing the three iterator methods (`nextElement`, `hasMoreElements`, and `reset`), some designers of lists provide an explicit ``current element''.
• With an explicit current element, you can
• `advance` the current element
• `back-up` the current element
• `delete` the current element
• `add` an element before or after the current element
• `find` an element and move the cursor to that element
• `move` the cursor to the front or back of the list
• ...
• What are the implications of including a cursor?
• The list must be ordered
• You have to be very careful in documenting your preconditions and postconditions for these and other methods. (We'll look at some.)

• Note that our cons-based implementation of lists (typically called linked lists) have an interesting assymetry:
• It is O(1) to add to the front of the list
• It is O(n) to add to the back of the list
• Similarly,
• It is O(1) to add after the current element
• It is O(n) to add before the current element
• To eliminate this problem, some implementers put the links in both directions. That is, in addition to having a next link, each cons cell also has a previous link.

## Vectors

• Java provides a data type for expandable, array-like (and also list-like) objects that are accessible by element.
• These structures are called Vectors.
• Do Lab X2.2

## History

Tuesday, 10 August 1999

• Created as a blank outline.

Monday, 1 November 1999

• Filled in the details.

Back to Project Discussion. On to Introduction to Linear Structures.

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.