Instructions
Practice Problems
Problem 1
Problem 2
Version: 5.2.1

Assignment 7

Goals: Practice designing methods in the presence of mutation. Learn to abstract over the data types (using parametrized types).

Instructions

The names of the projects and some of the project files must be exactly the same as specified in the assignment. Failure to do so makes it impossible for the graders to run your submission and results in immediate loss of at least 50% of the homework credit.

Make sure you follow the style guidelines for code indentation.

You will submit this assignment by the deadline using the Web-CAT submission system.

With each homework you will also submit your log file named pairxxx.txt where you replace xxx with your pair number.

On top of every file you submit you will have the names of both partners, and the pair number.

The .txt file will be the log of your work on this assignment. Each log entry will have data and time, who was present (one or both of the partners) and a short comment decribing what you were working on.

Due Date: Friday, October 26th, 9:59 pm.

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1

Problem 2 from the previous assignment introduced a mutable linked list data structure.

Create a project with the name HW07Problem1.

Here we extend what we learned in the the last lab and the last homework. We would like to build a list in such a way that we can start either at the front, or at the back, and move through the list in either direction. In order to do so, we have decided on the structures to represent the following scenarios:

            +-------+

            | Deque |

            +-------+

            | node  |--+

            +-------+  |

                +------+

                |

                v

          +----------+

          | Sentinel |

          +----------+

          | ""       |

      +---| next     |

      |   | prev     |-----------------------------+

      |   +----------+                             |

      |                                            |

      v                                            v

+----------+   +----------+   +----------+   +----------+

| Node     |   | Node     |   | Node     |   | Node     |

+----------+   +----------+   +----------+   +----------+

| "abc"    |   | "bcd"    |   | "cde"    |   | "def"    |

| bcdnode  |-->| cdenode  |-->| defnode  |-->| sentinel |

| sentinel |<--| abcnode  |<--| bcdnode  |<--| cdenode  |

+----------+   +----------+   +----------+   +----------+

Each node now has two links, one to the next item in the list and one to the previous node in the list.

The Sentinel node is always present. It does not contain any useful data, i.e. the data field may be either null, or for the list of Strings the empty String. Its role is to provide the link to the head of the list and to the tail of the list.

The Deque is a wrapper class that contains one field, the Sentinel node for this list. So an empty list would have the following class diagram:

     +-------+

     | Deque |

     +-------+

     | node  |--+

     +-------+  |

+----+   +------+

|    |   |  +----+

|    |   |  |    |

|    v   v  v    |

|  +----------+  |

|  | Sentinel |  |

|  +----------+  |

|  | ""       |  |

+--| next     |  |

   | prev     |--+

   +----------+

Problem 2

The data structure you have built in the previous problem is very useful, except for the fact that the data in the list can only be of the type String.

Create a project with the name HW07Problem2.

Import into it your solution to the previous problem.