Skip to main content
ICT
Lesson AB29 - Linked List
 
Main Previous Next
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 AB29.2 page 15 of 16

OrderedList

Background:

This lab assignment will use a text file, ‘file20.txt’, which is similar to the one used in the binary search Lab Assignment A19.1, Store. The file has been saved in random order by id number. Your program must build an ordered linked list based on the id field. The ordered list should be implemented as a SinglyLinkedList of type ListNode.

Assignment:

  1. Here are some of the specifications for the methods to be added to the SinglyLinkedList class:

    1. You are to write a method insert that builds the linked list in order based on the id value.

    2. A find method will check the list for a specific id value, returning a reference to such a node if the value exists in the list. If the value is not found, the method should return a null value.

    3. A remove method will remove unwanted data from the linked list.

    4. Write a clear method that clears the entire list.

    5. Write a loadData method.

    6. Code a recursive printBackward method that prints out the linked list contents in reverse order.

  2. Write a testing method with the following specifications.

    1. A method addLast is provided which builds the list just as in Lab Assignment AB29.1, List1. The list will be built in the same order as it exists in the data file. The routine that reads the data from the text file has been separated from the method to insert the information into the linked list. See the code in the program shell.

    2. The find method returns a null value.

    3. The remove method returns a null value.

    4. The clear method is stubbed out as a print statement.

    5. The printBackwards method is stubbed out as a print statement.

    6. The size method returns 0.

    7. Methods to read the data file and print the list are provided.

Instructions:

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

  2. Print out the entire source code.

  3. Include a printed run output of the following:

    1. The entire list printed in ascending order. Include a call of the size method and print the number of nodes.

    2. Print the list backward using the recursive printBackward method. Do not worry about printing a line number in this algorithm.

    3. The id’s you searched for and their corresponding inventory amounts. Your instructor will specify which id values to search for.

    4. Delete id values as specified by your instructor. Print the abbreviated list after values have been deleted and include a call to size.

    5. Clear the entire list of all nodes. Call the size method one last time.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.