Can you write a function that takes 2 vectors as parameters and returns a larger vector containing the two vectors
Example
Vector a: 1 2 3 4 5
Vector b: 6 7 8 9 10
Concatenated vector: 1 2 3 4 5 6 7 8 9 10
In C++
#include <vector>
#include <iostream>
#include <iterator>
// this is the function which concats two vector and prints
result data
void concat(std::vector<int>& a, const
std::vector<int>& b) {
a.insert(a.end(), b.begin(), b.end());
std::copy(
a.begin(),
a.end(),
std::ostream_iterator<int>(std::cout, " ")
);
}
int main(int argc, char** argv) {
std::vector<int> a{1,2,3,4,5};
std::vector<int> b{6,7,8,9,10};
concat(dest, src);
return 0;
}
In Java:
import java.util.Vector;
public class MergeVector {
static void concat(Vector<Integer> Va, Vector<Integer> Vb) {
Vector<Integer> merge = new Vector<Integer>();
merge.addAll(Va);
merge.addAll(Vb);
System.out.print("Concatenated Vector: ");
for(Integer in: merge) {
System.out.print(in +" ");
}
}
public static void main(String[] args) {
Vector<Integer> Va = new Vector<Integer>();
Vector<Integer> Vb = new Vector<Integer>();
Va.add(1);
Va.add(2);
Va.add(3);
Va.add(4);
Va.add(5);
Vb.add(6);
Vb.add(7);
Vb.add(8);
Vb.add(9);
Vb.add(10);
concat(Va, Vb);
}
}
Output:
Can you write a function that takes 2 vectors as parameters and returns a larger vector...
Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...
ANSWER USING PYTHON Write a recursive function that takes 2 sorted lists as arguments and returns a single, merged sorted list as a result. For example, if the two input lists are [0, 2, 4, 6, 8] and [1, 3, 5, 7, 9], the returned result should be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Remember that you can add lists in Python using the + operator ([0] + [1,2,3] = [0,1,2,3]) and can take slices of...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...
Python Write a function (named largest_of_three) that takes three parameters and returns the largest. You can assume the parameters are either floats or ints.
1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...
C++, Create a function called larger which takes two integers as its parameters and returns the larger of the two integers
Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...
Write a recursive function named multiply that takes two positive integers as parameters and returns the product of those two numbers (the result from multiplying them together). Your program should not use multiplication - it should find the result by using only addition. To get your thinking on the right track: 7 * 4 = 7 + (7 * 3) 7 * 3 = 7 + (7 * 2) 7 * 2 = 7 + (7 * 1) 7 *...
Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...
Write a function called find_max that takes a two-dimensional list as a parameter and returns the number of the row that sums to the greatest value. For example, if you had the following list of lists: list = [[1, 2, 3], [2, 3, 3], [1, 3, 3]] The first row would be 6, the second 8 and the third 7. The function would, therefore, return 1. You can assume the passed in list of lists has at least one row...