Question: Write a method called fromCounts that converts an ArraylntList of counts into a new ArraylntList of values. Assume that the ArraylntList that is called stores

 Write a method called fromCounts that converts an ArraylntList of counts

Write a method called fromCounts that converts an ArraylntList of counts into a new ArraylntList of values. Assume that the ArraylntList that is called stores a sequence of integer pairs that each indicate a count and a number. For example, suppose that an ArraylntList called list stores the following sequence of values This sequence of pairs indicates that you have 5 occurrences of 2, followed by two occurrences of -5, followed by 4 occurrences of 3, and so on. If we make the following call ArrayIntList list2 list.fromCounts (); Then the variable list2 should store the following sequence of values [2, 2, 2, 2, 2, -5, -5, 3, 3, 3, 3, 4, 4, 1, 0, 17, 17] You are writing a method for the ArraylntList class discussed in lecture public class ArrayIntList f private int[] elementData; // list of integers private int size; // current # of elements in the list You may assume that the ArraylntList that is called stores a legal sequence of pairs (which means it will always have an even size) and that the default constructor for ArraylntList will construct an array of sufficient capacity to store the result. Your method should not change the original list. If the sequence of pairs is empty, the result should be an empty list. You may call the ArraylntList constructor, but otherwise you may not call any other methods of the ArraylntList class to solve this problem. You are not allowed to define any auxiliary data structures (no array, String, ArrayList, etc), and you may not change the original list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!