Merging Two Arrays
Implementation of Merge Algorithm
Procedure :
Parameters : 3 arrays (2 sorted arrays of size n1 and n2 respectively and an empty array of size n1+n2 to merge into), size of array 1 and size of array 2.
Initialise i, j and k with 0.
i is used to keep track of first array, j is used to keep track of second array and k is used to keep track of merged array.
Compare the values in first array and second array for each index.
Assign the lower among those two values to the merged array and increment the index pointers accordingly.
Transfer remaining elements (if any) to the merged array.
Merge function :
Contributed by Nitin Ranganath
Last updated