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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started