Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will implement more complex list manipulations, in the same style as you did simpler tasks in the lab. Use this link
In this assignment, you will implement more complex list manipulations, in the same style as you did simpler tasks in the lab. Use this link to accept the assignment: https://classroom. github.com/a/qJrmrHGL 1 Concerning List Computation maximum(list) The first task in this homework is to compute the maximum value in a list of integers. If the list is empty, you should return the minimum possible integer value (Integer.MIN_VALUE). You should compute the maximum using the NORMAL list traversal idiom. 2 Concerning Copying and Reversing Lists The next few tasks involving copying and reversing lists: copyList(list) The textbook defines a listCopy method that performs the same task, but it uses addAfter which we will not be using, and uses a "while" loop. You will need to keep track of the last node of the result in this task (and several other tasks in this homework). The textbook uses the name "copyTail" for the same purpose. reverseCopy(list) This task involves creating a new list that has the same elements as the list coming in, but in reverse order. Implement this using the NORMAL loop idiom. It's actually very simple, since lists are built from back to front. reverseDestructive(list) This task involves performing a "destructive" operation on a list. A destructive operation does not actually destroy anything, rather it is "recycling" the nodes from the input list(s) to construct the output. It's called "destructive" because the input list(s) cannot be used afterwards. Destructive operations are more efficient of space. The algorithm you need to implement uses the same idea as the non-destructive version above: we build the result list back to front, but instead of creating "new" nodes, we reuse the nodes from the input list. Here, a "while" loop should be used instead of a "for" loop idiom. The loop will successively remove nodes from the input (i), change the pointers and then put them on the result (r). For example: page 1 of 3 3 Concerning "Zipping" Lists The next three tasks concerning zipping lists: taking two lists and combining them into one by taking one element from each list alternatively. So if we zip (1,10,100) with (3,4,5), we end up with (1,3,10,4,100,5). We're also interested in the reverse operation that divides a single list into two lists by "unzipping" it. evensCopy(list) This method constructs a new list with the "even" elements (index 0, 2, 4, etc.) of the argument. For example if the list passed in is (1,2,3,4,5) the result is a new list (1,3,5). As perhaps obvious, this task is non-destructive, it creates new nodes to hold values. It can be seen as a variant of the copyList task. unzipDestructive(list) This method "unzips" a list destructively into two lists using the same nodes: the "evens" part starts with the same head node and the "odds" sub-list starts with the second node. It returns the head of the "odds" sub-list (that is, the second node of the original list). It creates no nodes; everything is done with the existing nodes. We end up with two lists (and two terminating null pointers!). For example: zipCopy(list1,list2) This method zips two lists together without disturbing the existing lists. We implement this method for you by copying the arguments and then calling the next (destructive) version of "zip." Don't change it! If it doesn't work, it merely means that your destructive zip method is failing. zipDestructive(list1,list2) This method does the opposite of the unzipDestructive: zips together two lists destructively. If one of the lists ends early, we put all the other lists nodes at the end of the result. In other words, we don't need to change the internal pointers of the remainder of the other list. The order the two lists are passed makes a difference as seen in the two following pictures: The homework repository has an optional task as well. You may do it for additional practice working with nodes, but it is not part of your assignment grade. 4 Files In the git repository for this assignment, we provide the following files: - src/Test IntNode. java JUnit test cases. Do not modify this file. - src/edu/ukm/apc430/IntNode.java The IntNode class and partially implemented tasks: edit this file! APC 430: Applied Data Structures \& Algorithms Homework \#4 5 What you need to do You need to complete the tasks in IntNode, except for the optional task. The class must be pushed to your homework4 git repository before the deadline
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started