Question: C++ help How can I remove duplicate numbers for the output? output should be: 1,2,3,5,6,7,8 #include using namespace std; void mergeArrays(int arr1[], int arr2[], int
C++ help
How can I remove duplicate numbers for the output?
output should be: 1,2,3,5,6,7,8
#include
using namespace std;
void mergeArrays(int arr1[], int arr2[], int n1, int n2)
{
int i = 0, j = 0;
// Traverse both array
while (i { if (arr1[i] < arr2[j]) cout << arr1[i++]; else cout<< arr2[j++]; } while (i < n1) cout< while (j < n2) cout< } // Driver code int main() { int arr1[] = {1, 3, 5, 7}; int n1 = sizeof(arr1) / sizeof(arr1[0]); int arr2[] = {2, 3, 5, 6, 8}; int n2 = sizeof(arr2) / sizeof(arr2[0]); cout<< "Sorted array: "; mergeArrays(arr1, arr2, n1, n2); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
