Question: 4. Write a function called rotateRight that takes an array of integers as an argument and rotates values in the array one to the right

4. Write a function called rotateRight that takes an array of integers as an argument and rotates values in the array one to the right (i.e., one forward in position), shifting the value at the end of the array to the front. For example, if the array called list stores [3, 8, 19, 7] before the function is called, it should store [7, 3, 8, 19] after the function is called. Another call on rotateRight would leave the list as [19, 7, 3, 8]. Another call would leave the list as [8, 19, 7, 3].

5. Write a function count that takes an array of integers and a target value as parameters and returns the number of occurrences of the target value in the array. For example, if an array called list stores the sequence of values [3, 5, 2, 1, 92, 38, 3, 14, 5, 73] then the following call int n = count(list, 3); would return 2 because there are 2 occurrences of the value 3 in the list.

6. Write a function called stretch that takes an array of integers as an argument, and returns a new array twice as large as the original that replaces every integer from the original list with a pair of integers, each half the original, and then returns it. If a number in the original list is odd, then the rst number in the new pair should be one higher than the second so that the sum equals the original number. For example, suppose a variable called list stores the sequence of values [18, 7, 4, 24, 11]. The number 18 is stretched into the pair (9, 9), the number 7 is stretched into (4, 3), the number 4 is stretched into (2, 2), the number 24 is stretched into (12, 12) and the number 11 is stretched into (6, 5). Thus,the call: stretch(list); should replace list with the following list which is twice the length of the original: [9, 9, 4, 3, 2, 2, 12, 12, 6, 5]

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!