CSE 222 Lab #5


Please turn in whatever you have by the deadline, as no late submissions will be accepted for this lab assignment.

Objectives

The Problem

The problem is to complete and carefully test implementations of all the operations of abstract template List_Retreat, by building a representation that involves a doubly-linked list of nodes using "raw C++" pointers. List_Retreat extends List_Kernel with one more operation, Retreat, which has the following specification:
procedure Retreat () is_abstract;
/*!
    requires
        self.left /= empty_string
    ensures
        self.left * self.right = #self.left * #self.right and
        |self.left| = |#self.left| - 1
!*/
This additional operation gives the client the ability to move backward one position at a time.  The original List_Kernel allows only incremental forward movement; moving backward is possible only by "jumping" all the way back to the start using Move_To_Start. Retreat is just the inverse of Advance.

Note that Retreat can be implemented by layering, i.e., by extending any implementation of List_Kernel by layering just as we've done for many other extensions earlier in the course.  You should know how to write that code!  However, the execution time of the layered implementation is linear in the length of the left string of the list.  The challenge here is to implement List_Retreat so all the operations (except Finalize/destructor) take constant time, independent of the sizes of the left and right strings of the list.  This is possible only by implementing all the List_Retreat operations directly, i.e., not by layering on an existing implementation of List_Kernel but by creating an entirely new implementation that is based on a doubly-linked list data structure.

Method

Here's what to do:

Possible Maintenance Activities

Here are some questions about possible maintenance activities involving this program:

Any extra work is strictly optional, for your own benefit, and will not directly affect your grade.