CSC 225 Fall 2017 Laboratory 2 Part B: Programming Questions

The aim of this lab is to prepare you for the programming exercise on Assignment #1 Part A. It also should help you with Questions 5-6 on Assignment #1 Part B.

The java code for this lab is in:

  1. ListNode.java
  2. LinkedList2.java
To save them, right click on the hyperlinks and choose the "Save as" option.

To run the Java code I typed:
javac *.java
java LinkedList2 < in.txt > out.txt

  1. Step through the code on these four inputs:
    1 6
    
    2 23 18
    
    3 3 7 5
    
    4 19 32 54 8
    
    For each case, how many times is the statement current= current.next executed?
  2. How much work does readRear do on an input of size n?
  3. Modify the code for readRear so that the time it takes on an input of size n is proportional to n.

Please also bring to the lab any questions you have about assignment #1 Part A or Part B.

Thought Questions:

The lab method for reading values into a linked list is in the LinkedList2 class and has a method header like this:
public boolean readRear(Scanner in)

The one I have asked you to write on the assignment has:
public static LinkedList readBigInteger(Scanner in)

What are the differences between how the program interacts with these two implementations? What are the advantages and disadvantages of each one (including possible bugs that might arise)?


CSC 225 Labs / maintained by Wendy Myrvold / wendym@UVic.ca / revised Sept. 10, 2017