Algorithm question: in-place multi-bringToFront?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri May 29 12:45:59 UTC 2020
On 5/28/20 7:47 PM, H. S. Teoh wrote:
> 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.
Is that the complement of
https://dlang.org/library/std/algorithm/mutation/remove.html? In that
case it should be adaptable from it with ease.
More information about the Digitalmars-d
mailing list