Recitation 9

Introduction

Last week, we saw how to implement lists using differnt underlying representations. In recitation this week, you will practice interacting/modifying the underlying representations as you add new features to the two implementations from last week. Additionally, in preparation for trees, you will practice working with and manipulating linked lists.

New Operations for ALists and LLists

Implement the operations described below for both the AList and the LList.

  1. Suppose that you want an operation for the ADT list that returns the position of a given object in the list. The header of the method should be as follows:
    public int getPosition(T anObject)
    where T is the generic type of the objects in the list.
  2. Suppose that you want an operation for the ADT list that moves the first item in the list to the end of the list. The header of the method should be as follows:
    public void moveToEnd()
  3. Implement an equals method for the ADT list that returns true when the entries in one list equal the entries in a second list.

New Operations for LLists

Implement the operations described below for the LList. If you want to, you may also do so for the AList.

  1. Add a constructor to the class LList that creates a list from a given array of objects. Consider at least two different ways to implement such a constructor. Which way does the least amount of work?
  2. Suppose that a list contains Comparable objects. Implement a method that returns a new list of items that are less than some given item. The header of the method should be as follows:
    public LList<E> getAllLessThan(Comparable<E> anObject)
    Make sure that your method does not affect the state of the original list.

Submission and Grading

This is for your practice. You should be able to complete some of the functions by the end of recitation. If you complete a function, call the TA over to look over your function to make sure it is correct. If you do not have time to complete the programs before the end of recitation, you have the option of uploading it to CourseWeb once you are finished to receive feedback on it from the TA. If you upload it after Monday, November 16, please email the TA so he knows to look at it.