Go through the second array and look for each element in the first array.
Use a bool array to mark which elements are already taken (or replace them with an invalid value in the first array, if there is such a value).
You can't really set the list items in arry1 to a null value unless you know with complete certainty that that value is not ever going to be in arry2; boolean array would be a much better option.
This is how I did it, you can simplify my code a lot, but the idea is the same.
#include <iostream>
#include <vector>
usingnamespace std;
int main(int argc, char** argv) {
//Both arrays you provided
int list_a[8] = { 2, 2, 2, 3, 1, 0, 0, 0 };
int list_b[8] = { 3, 2, 2, 2, 1, 0, 0, 0 };
//Position in array
int pos = 0;
//Vectors of arrays you provided
vector<int> a( list_a, list_a + sizeof(list_a)/sizeof(int) );
vector<int> b( list_b, list_b + sizeof(list_b)/sizeof(int) );
//Boolean Array Athar suggested
vector<bool> temp( false, list_b + sizeof(list_b)/sizeof(int) );
//Empty third array
vector<int> c;
while( !b.empty() )
{
//Reset the position to the front of array A each iteration
pos = 0;
//Increases the position if the values aren't the same, OR if that position has been used before
while( ( a[pos] != b.front() ) || ( temp[pos] == true ) )
pos++;
b.erase( b.begin() );
c.push_back( pos );
temp[pos] = true;
}
//Print out third array
for( uint i = 0; i < c.size(); i ++)
cout << c[i] << " ";
return 0;
}