20-CS-122-001 Computer Science II Spring 2012
Map the elements of one list to another

Virtual functions, classes, inheritance, lists, queues, stacks, applications

Given: two lists L1 and L2 that are known to be permutations of one another.
Problem: Output an array perm such that perm[i] is the index of the element of L1 that is at index i of L2.
Example:
   L1 = 45 22 89 66 11 71 90 23 24 10 17
   L2 = 10 11 17 22 23 24 45 66 71 89 90
then
   perm[0] = 9, perm[1] = 4, perm[2] = 10, perm[3] = 1, perm[4] = 7, perm[5] = 8
   perm[6] = 0, perm[7] = 3, perm[8] = 5,  perm[9] = 2, perm[10] = 6

Algorithm:
    Open a file and read lists L1 and L2 into arrays.
    Repeat the following for all i from 0 to the length of L2 minus 1:
       Repeat the following for all j from 0 to the length of L1 minus 1
          If L2[i] = L1[j] set perm[i] = j and break;
    Output perm.