I figured out n lg(n) algorithm;
I created a new array called location[].
While I am creating my master list, I store the location of each data value into location. For example, if in the master list 5 is in location 10, I do location[5] = 10. Now I have a way of looking up the location of any data value in constant time.
I then did a qsort(array1, length of array1, sizeof(int), compare);
Where compare...
User Profile
Collapse
-
tc18a started a topic Algorithm for sorting array of integers w/ respect to another array (c code would bein CAlgorithm for sorting array of integers w/ respect to another array (c code would be
I'm looking for a fast algorithm for sorting an array of integers with respect to a master list.
For example:
Master List: 7 3 9 1 32 6 5 4 99 100 201 13
Array that needs to be sorted array1: 1 5 4 3 6
The "sorted" array would be: 3 1 6 5 4
The order of the array that needs to sorted is originally random. Neither the master list nor the array that needs to be sorted will...
No activity results to display
Show More
Leave a comment: