Hi guys,
Lets see if you can help me with this one...
I need to compare two lists of numbers that should contain the same values one by one, but obviously thats not the case because sometimes one of the sources misses a value. I must log when a discrepancy is found.
list1: [5,4,6,7,10]
list2: [5,6,7,9,10]
As you can see, the list2 misses the value 4, and list1 misses the value 9.
Elements are not ordered but there are never two identical values in a row:
Impossible: [4,5,5,6]
Possible: [4,5,6,5]
My first idea is to go through the list one by one. Here some pseudo-code:
while (!list1.isEmpty() && !list2.isEmpty()){
if (list1[0] = list2[0]) then
list1.remove(0)
list2.remove(0)
else (list1[0] != list2[0]) then
LOG ERROR but who miss the value?
now what?
My problem is that I dont know what to do when two values dont match, because in that moment I dont know if the mismatch is because the value in list1 is not in list2, or the other way round.
One option is to check if the next value in one of the list is the current one in the other, but what if there are more than 1 value missed?
Your help would be much appreciated. Thanks
Edited by: pedroruiz on Feb 4, 2010 7:53 PM