-
July 16th, 2009, 08:23 PM
#1
compare two lists
I have two lists (structure undecided), each contains column A and column B. I primarily need to know which elements of column A in list1 are missing in list 2 column A, or which ones in list2 column A are missing from list1 column A. I have no idea where to begin here. Of course a nested loop could achieve it, but there must be some elegant method.
THEN, for those matches where list1colA==list2colA, I also need to know whether or not list1colB==list2colB. I figure once the first question is answered, a single loop can determine this part, but if it can be combined with the above, that would be even better.
so for example, an ID and a timestamp for colA and colB
list 1:
Code:
col A colB
0 7:35
1 6:03
3 15:07
4 16:58
list2:
Code:
colA colB
0 7:35
1 8:19
2 3:02
4 16:58
So somehow it would know that colA=colA on 0,1,4, but timestamps are different on 1, and also that list2 has an extra#2 and list1 has an extra#3.
Just a nudge in the right direction is all I need.
-
July 16th, 2009, 08:29 PM
#2
Re: compare two lists
err I should say that list 1 and list2 are both unsorted. So list1 ID order could be:4,1,0,3...same for list2
-
July 16th, 2009, 09:36 PM
#3
Re: compare two lists
Well, you could use std::set_difference() to find which elements are in one but not the other. However, that would require you to sort the inputs first. Just about every "elegant" method either requires you to sort or hash the inputs.
-
July 16th, 2009, 10:19 PM
#4
Re: compare two lists
hmm. If theyre already sorted I could just do one pass through the lists and find the missing and extra and different_colB items. Would that be faster than a two pass set_difference?
-
July 17th, 2009, 12:11 AM
#5
Re: compare two lists
Perhaps slightly. Whether it's a big enough difference to warrant the more complex logic required is a design decision.
-
July 17th, 2009, 08:56 AM
#6
Re: compare two lists
hi di want to know abt usage of pointers and stuctures
-
July 17th, 2009, 09:04 AM
#7
Re: compare two lists
u der will u help me to grasp the concepts of class and objects
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|