IMPORTANT: Do not modify the provided toString method in the ListItem class, since our automated tests depend on the specific formatting it produces.
- Use the JUnit test cases in ListItemTest to guide the development of your methods, and continually test-as-you-go.
- Hints: Draw lots of pictures before writing any code. Try small examples and hand simulate how your algorithm will work. Use small lists for testing in JUnit so you can draw the corresponding pictures. Then, if things don't work as expected, use the debugger to examine the list structure itself in memory. To do this, set a breakpoint at a line in the test case where you want the debugger to pause. Then, choose "debug as" instead of "run as" in Eclipse. Use the "step over" and "step into" methods to single step through the code, and examine the list structure in the "variables" view by opening up the "next" references to see what they refer to.
duplicatethat takes no parameters and returns a new ListItem that begins a list containing the same numbers (but not the same ListItem objects) as the original list.
lengththat takes no parameters and returns the number of elements in the list. For example, the list (3 5 9 3 2 4) would have length 6.
stretchthat takes a positive number
nas a parameter and returns a new ListItem beginning a list in which each of the numbers in the original list is repeated
ntimes. For example, if the original list is ( 6 7 6 9 ) and the parameter value is 2, then the new list returned is ( 6 6 7 7 6 6 9 9 ).
findthat takes an integer
targetand returns the first ListItem in the list that contains the given number. If the target does not occur in the list, then
maxthat returns the largest number in the list. Hint: You know that the maximum value must be at least as large as the number in the first ListItem.
A recursive procedure
PARAMETERS: a ListItem reference, ls RETURN VALUE: a ListItem at the beginning of a list structure containing copies of the even numbers in given list. for example, given input list ( 3 2 6 9 ), the return value would be the list ( 2 6 )
When you done with this lab, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so