|
comparing integer lists
I have two small arrays of integers. (I don't expect more than 16 elements in each array) No integer occurs more than once in an array. Integers are sorted from least to greatest, though they are not necessarily consecutive.
What's an efficient way to diff them, so I get the elements in each array that aren't in the other?
(I do want two resulting arrays, for the elements that were only in array 1, and only in array 2)
The simple way I thought of was to iterate through the first away searching for matching elements in the second array. If one is found, both elements are deleted. The remaining arrays are the elements that were only in each array.
__________________
-- Marshal Horn
Last edited by kamocat : 25-07-2010 at 13:52.
|