sorting and merging of arrays of unknown sizes

N

Nick

ramu said:
Hi,
Can anyone tell me how to sort and merge two arrays of
"unknown sizes"?

Firstly, people won't write code for you - if you show what you've done
and what your problems are they'll try to help you improve it and sort
out the bits you are having problems with.

Secondly, your specification is too vague anyway. Are they unknown at
execute time or only at compile time? Are they of a known type or
should the code cope with different types? Are they pre-existing arrays
or are they actually data in files? Are they big enough that they can
both fit in "memory" at the same time?

If you do part 1, you'll avoid the problems in part 2.
 
D

Dann Corbit

Hi,
Can anyone tell me how to sort and merge two arrays of
"unknown sizes"?

If they are arrays, that implies that they are in memory.
1. Call qsort on both arrays
2. Find out which array has the smallest element on top.
3. Emit the smallest element and move to the next position.
4. If both arrays are empty, then stop. Otherwise go to step 2

Not exactly rocket science.

If your use of the term 'array' just implies some arbitrary list, then
if the array is too large to fit into memory, then replace step 1 with
"1. Call external sort on any arrays too large to fit into RAM"

HTH

P.S.
Your post does not belong here. Try next time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top