Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Define a function int * shuffle (int * p1, int len1, int * p2, int len2) that shuffles the arrays where the first

In C++

Define a function int * shuffle (int * p1, int len1, int * p2, int len2) that "shuffles" the arrays where the first array has base address p1 with length len1 and the second array has base address p2 with length len2. The function should return a dynamically allocated array containing all the shuffled elements. To shuffle, we start with element zero of p1, followed by element zero of p2, followed by element one of p1 and so on until the elements of (at least) one of the arrays are exhausted. If there are still elements remaining to process from the other array, then we just tack them on at the end. You must use pointer notation throughout the function. (No square brackets except to allocate an array.) Sample driver below. #include using namespace std; void print(int * nums, int length); int * shuffle (int * p1, int length1, int * p2, int length2) ; int main() { int len1, len2; cin >> len1 >> len2; int nums1[] = {1,3,9,13,17}; int nums2[] = {4,6,14,18,20}; int * temp = shuffle(nums1,len1,nums2,len2) ; print(temp, len1 + len2) ; delete [] temp; return 0; } void print(int * nums, int length) { for (int i = 0; i < length;i++) cout << *(nums + i) << " "; cout << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago