Ask Question
18 September, 21:57

Write a function merge that merges two lists into one, alternating elements from each list until the end of one of the lists has been reached, then appending the remaining elements of the other list.

+4
Answers (1)
  1. 19 September, 00:17
    0
    The program that merges two lists or two arrays is written below;

    Code:

    void main void

    {

    char [] arr1 = {'1','2','3'};

    char [] arr2 = {'a','b','c','d','e'};

    int l1 = arr1. length;

    int l2=arr2. length;

    int l3=l1+l2;

    char [] arr3=new char[l1+l2];

    int i=0;

    int j=0;

    int k=0;

    int m=0;

    int r=0;

    if (l1
    r=l1;

    else

    r=l2;

    while (m
    {

    arr3[k++]=arr1[i++];

    arr3[k++]=arr2[j++];

    m++;

    }

    while (k
    {

    if (l1
    arr3[k++]=arr2[j++];

    else

    arr3[k++]=arr1[i++];

    }

    for (int n=0; n
    {

    System. out. print (arr3[n]+" ");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function merge that merges two lists into one, alternating elements from each list until the end of one of the lists has been ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers