Write a method stutterTwo
that could be added to the LinkedIntList
class that doubles the size of the list by replacing every pair of neighboring integers a,b with two consecutive copies of that pair, a,b,a,b (a total of four integers come from the original two). Suppose a LinkedIntList
variable named list stores the following elements from front to back:
[18, 4, 27, 9, 54, 5, 63]
If you made the call of list.stutterTwo();
, the list would then store the elements in this order:
[18, 4, 18, 4, 27, 9, 27, 9, 54, 5, 54, 5, 63]
If the list has an odd number of elements the last element should not be stuttered. If the list is empty, its contents should not be modified.
Assume that you are adding this method to the LinkedIntList
class as defined below:
public class LinkedIntList {
private ListNode front; // null for an empty list
...
}