Skip to main content
ICT
Lesson AB27 - Java Lists and Iterators
 
Main Previous
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

LAB ASSIGNMENT AB27.1 page 9 of 9

MergeList

Background:

An unordered linked list is difficult to sort given its sequential nature, but a recursive merge sort works well for linked lists. The algorithms required (split and merge) will provide excellent practice in working with the java.util.LinkedList and ListIterator classes.

Here are the three steps for a recursive merge sort:

  1. Split the list into two smaller lists.
  2. Recursively sort each of these lists using merge sort.
  3. Merge the two sorted lists together.

Review your code for the merge and mergeSort methods from Lesson A18, Merge and MergeSort, to help you to implement the same concept with linked lists.

Assignment:

  1. The linked list should be of type java.util.LinkedList.

  2. The data file to be used in this lab is (file20.txt).

  3. Build the initial linked list from (file20.txt) following this logic:

    place each new Id/Inv pair that is read from the data file at the beginning of the list

    Therefore, the first values read from the data file will end up last in the list.

  4. The recursive merge sort algorithm will need the supporting algorithms of splitting and merging lists. List iterators should be used to implement these methods.

  5. Your program should consist of the following sequence of scripted events:

    - Load the data file and build the initial list
    - Print the linked list - it is unordered
    - Recursively merge sort the list
    - Print the linked list - it is now sorted
    - Reverse the linked list
    - Print the linked list - it is now in descending order

  6. If your teacher so chooses, you will be provided with a program shell consisting of a MergeList class containing a main method, and the Item class. All of the code development will be in the MergeList class.

Instructions:

  1. Modify and write code as necessary to satisfy the above specifications.

  2. Print out the source for the MergeList class.

  3. Turn in your source code along with the run output.

 

Main Previous
Contact
 © ICT 2006, All Rights Reserved.