View Single Post
  #1   Spotlight this post!  
Unread 25-07-2010, 13:45
kamocat's Avatar
kamocat kamocat is offline
Test Engineer
AKA: Marshal Horn
FRC #3213 (Thunder Tech)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 2008
Location: Tacoma
Posts: 894
kamocat is just really nicekamocat is just really nicekamocat is just really nicekamocat is just really nicekamocat is just really nice
Send a message via AIM to kamocat Send a message via MSN to kamocat
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.