Algorithm question: in-place multi-bringToFront?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 28 23:47:50 UTC 2020


Just pickin' yall's smart brains:

Given an array A and a set of indices into the array, is there a fast
algorithm for rearranging A in-place so that the elements at the given
indices are moved to the front?

E.g.: A = [ 0, 1, 2, 3, 4, 5 ], index = [ 1, 3, 5 ]

The result should have 1, 3, and 5 at the front of the array (the exact
order is unimportant).

For efficiency considerations, assume the size of the index is
relatively small, but the array itself may be quite large, so scanning
the entire array or copying large chunks of it is undesirable.


T

-- 
Customer support: the art of getting your clients to pay for your own incompetence.


More information about the Digitalmars-d mailing list