The problem is that you are stuck with lookups into the larger array and that's O(n). Your best choice if you have to do this a lot and the larger array isn't so large that memory usage would make it unfeasible, would be to make a hash keyed by the elements in the larger array where the values are those elements' indexes. Otherwise, what you are doing is pretty reasonable.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: sort an array according to another array
by sauoq
in thread sort an array according to another array
by glwtta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |