Ask Question
8 August, 15:58

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. 8 August, 18:37
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers