Question: 1) Using c++, write a void function named insertAtFront, that takes two parameters: a vector of integers and an integer value, then insert the integer
1) Using c++, write a void function named insertAtFront, that takes two parameters: a vector of integers and an integer value, then insert the integer value from the second parameter into the vector and this inserted value becomes the first item in the vector. For example, after the following statements in the main:
vectorvalues(5); values[0] = 24; values[1] = 3; values[2] = 78; values[3] = -5; values[4] = 57;
int item = 62 insertAtFront(values, item);
then values[0] is 62, values[1] is 24, values[2] is 3, values[3] is 78, values[4] is -5 and values[5] is 57. The function uses the following header:
void insertAtFront(vector& vecA, int item)
2) A run is a sequence of adjacent repeated values. Write a function run_length() that counts the length of the longest run in a sequence stored in a vector. If there is no adjacent repeated values in a sequence, then your function should return 1. (A single number is a run with length of 1) For example, the longest run in the vector with elements:
1255412432222365566631
has length 4 (for the adjacent repeated values of 2 in this example). The function uses the following header:
int run_length(vectornums)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
