in reply to Re: joining and sorting arrays
in thread joining and sorting arrays

No. Fairly easy to find counter examples. Just start with a small working example:

0 1 2 3 4 5
then take two numbers near the middle that aren't 1 apart and add 1 to one of them and subtract 1 from the other:
0 2 2 3 3 5

Seems that a correct, fast soltuion would be a modified merge sort. I have a working example of such but I'm dubious of posting it as it now occurs to me that this is would be a fairly good, fairly advanced homework problem while I'm having a hard time coming up with a practical use for such.

Perhaps you should tell us why you need this?

Update: Just realized that the problem is even simpler than I first understood. I initially thought that the last example was a "good" example, not a "bad" example. I've updated my counter example to reflect that.

This also means that a modified merge sort is overkill. Instead I'd just stuff the first element of each list into a hash and start at 0, look up the list that starts there, move down it verifying sequentialness, look up the list that starts at the next number, etc. I'm still not posting demonstration code, however, for most of the reasons I stated.

        - tye (but my friends call me "Tye")