Question: Below are some java methods I need help creating for a Linked List. Please use generics. You don't have to do all of them, any
Below are some java methods I need help creating for a Linked List. Please use generics. You don't have to do all of them, any will help. I can adjust the code to fit my specific program, just need the logic part of the code.
1.MyLinkedList
Returns a new list that is a (shallow) copy of this list.
[Update Nov. 15] Your implementation of clone will make a deep copy of the list but a shallow copy of the data stored in each node. Create a new list and new nodes, but the new list will be a series of nodes created with something like:
Node nodeCopy = new Node(currNode.data, null);
// more code to insert nodeCopy into the new list
2. boolean equals(Object o)
This method overrides the equals method (found in the Object class). Since you are overriding the equals method, it must have the same signature as the one found in the Object class! As a result, you will need to cast the Object parameter to a variable of appropriate type (MyLinkedList
MyLinkedList
Once you've made the cast, the method should then compare list with this list for equality. The method returns true if and only if both lists have the same size and all corresponding pairs of elements in the two lists are equal. You must not create any other list in this method, and your solution must not modify the original lists.
3. doubler()
Modifies the list so that each element is replaced by two adjacent copies of itself. For instance, if the list is [1,2,3,3,4], then list.doubler() should modify the list into [1,1,2,2,3,3,3,3,4,4].
4. sublist(int i, int j)
Returns a new list consisting of the elements of the original list starting at index i and ending at index j-1.
Other methods
It is OK to add other methods (helper methods) to complete the 12 methods described above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
