Question: Write a method called shift that rearranges the elements of a list of integers by moving to the end of the list all values that
Write a method called shift that rearranges the elements of a list of integers by moving to the end of the list all values that are in oddnumbered positions and otherwise preserving list order. For example, suppose that a variable list stores the values [10, 31, 42, 23, 44, 75, 86] . The call of list.shift(); should rearrange the list to store [10, 42, 44, 86, 31, 23, 75] . It doesn’t matter whether the value itself is odd or even; what matters is whether the value appears in an odd index (index 1, 3, 5, etc.). Also notice that the original order of the list is otherwise preserved. You may not construct any new nodes nor use any auxiliary data structures to solve this problem. You also may not change any data fields of the nodes; you must solve this problem by rearranging the links of the list.
Step by Step Solution
3.39 Rating (158 Votes )
There are 3 Steps involved in it
public void shift if front null frontnext null frontnext ListNode otherF... View full answer
Get step-by-step solutions from verified subject matter experts
