Merging Array

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 979 Views - Last Post: 19 February 2013 - 06:04 PM Rate Topic: -----

#16 Sandals456  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 02-February 13

Re: Merging Array

Posted 19 February 2013 - 01:18 PM

View PostAdak, on 11 February 2013 - 10:34 AM, said:

Sandals, do you want to:

*merge AND sort the two arrays into one array, at the same time, using a merge sort algorithm

or

*merge the array values first, THEN sort the array values, after they all get into one array.

In the first case, you would normally use a third array:
array 1\
        \
         -> array 3
        /
array 2/



But it CAN be done, it's just a bit more difficult to do it the first way, with only two arrays.

What do you need to do here?


I want to merge the two arrays and then sort them. I can only use the two arrays which is why array_1 has 18 elements and only 13 can be inputted, so that the other 5 elements from array_2 can be placed inside the first array.
Was This Post Helpful? 0
  • +
  • -

#17 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1086
  • View blog
  • Posts: 4,564
  • Joined: 09-June 09

Re: Merging Array

Posted 19 February 2013 - 06:04 PM

Quote

I want to merge the two arrays and then sort them. I can only use the two arrays which is why array_1 has 18 elements and only 13 can be inputted, so that the other 5 elements from array_2 can be placed inside the first array.


Alright, since your still struggling conceptually, here is some pseudo code. I can't really give any more direct help to the solution

Create two iterators, iter_1 to iterate over array_1, and iter_2 to iterate over array_2.

Iterate iter_1 from 13 - 17 & Iterate iter_2 from 0 - 4
set array_1[iter_1] = array_2[iter_2]

arrays are now merged
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2