Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I was working on a code to reverse a linked list by splitting it recursively and cant figure out the code. The image description of
I was working on a code to reverse a linked list by splitting it recursively and cant figure out the code. The image description of what the code should do is given and the WRITTEN-DESCRIPTION (very important-please read) is given above the image description. This code is supposed to be written in JAVA and is ONLY SUPPOSED TO USE THE REVERSE METHOD with only the level parameter.
3. public void reverse(int level) 130 marks] The reverse must operate recursively. First the list should be split into two lists, one with the first floor of n/2 entries and the other with the rest. You can use two new LinkedList objects each time you split the list in half but do not make any new ListNode objects. Then each of these lists should be reversed recursively. Then concatenate together the answers appropriately to get the final answer. The variable level is for debugging and represents the level of the recursive call. The initial call should be at level 0. If reverse is called from level k then the resulting invocation is at level k+1Step 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