logo Practice-It logo

stutterTwo

Related Links:
Author: Allison Obourn (on 2012/08/11)

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
    ...
}
Type your solution here:


This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.