Write a function shuffle that takes as input parameter arguments two vectors of integer values and returns a vector of integer values that combines the two input vectors by alternating between values from each of the two vectors.

Respuesta :

Answer:

This question is answered using C++

vector<int> shuttle(vector<int> vect1 , vector<int> vect2)  {  

  vector<int> result;

  for(int i=0;i<vect1.size();i++) {

      result.push_back(vect1[i]);

      result.push_back(vect2[i]);

  }

  return result;

}  

Explanation:

This defines the vector function with two vector arguments

vector<int> shuttle(vector<int> vect1 , vector<int> vect2)  {  

This declares result as an integer vector

  vector<int> result;

The following iterates through the vector arguments

  for(int i=0;i<vect1.size();i++) {

The next two lines combine the two input parameters into the result vector declared above

      result.push_back(vect1[i]);

      result.push_back(vect2[i]);

  }

This returns the vector of both input vectors

  return result;

}  

See attachment for complete program that include the main method

Ver imagen MrRoyal
fichoh

The function which combines two different vector variables is written in python using the Numpy module. The program goes thus :

import numpy as np

#import the Numpy module

vec1 = np.arange(3)

#a 1 - d vector array with 0, 1, 2

vec2 = np.arange(4,7)

#a 1 - d array vector array with 4, 5, 6

def shuffle(vector_1 , vector_2):

#initialize a function named shuffle which takes tow parameters

return np.concatenate((vec1, vec2))

#return a combined array of the vectors using the concatenate function

print(shuffle(vec1, vec2))

#A sample run of the program

Learn more : https://brainly.com/question/22288029

Q&A Education