0

If i have two arrays ,

A= [2,3,4] and B=[8,9,10].

How can i merge this two arrays.

Solution C=[2,3,4,8,9,10]

Please guide.

Swetha.P
  • 81
  • 2
  • 8
  • 1
    Sorted (as per your example) or unsorted? have you made any attempt? – Mike Feb 07 '13 at 14:42
  • Refer this: http://stackoverflow.com/questions/1700182/how-do-i-merge-two-arrays-having-different-values-into-one-array –  Feb 07 '13 at 14:43

1 Answers1

3
  1. Allocate space for array big enough for both A & B
  2. Copy all elements from A
  3. Copy all elements from B

If you mean merge and preserve some sort of order, then iterate over A & B simultaneously copying the next relevant(depending on your ordering criteria) value in to the next slot in the new array.

Nim
  • 33,299
  • 2
  • 62
  • 101