CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Posts
    8

    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.

  2. #2
    Join Date
    Jul 2009
    Posts
    8

    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

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  4. #4
    Join Date
    Jul 2009
    Posts
    8

    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?

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: compare two lists

    Perhaps slightly. Whether it's a big enough difference to warrant the more complex logic required is a design decision.

  6. #6
    Join Date
    Jul 2009
    Posts
    2

    Re: compare two lists

    hi di want to know abt usage of pointers and stuctures

  7. #7
    Join Date
    Jul 2009
    Posts
    2

    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
  •  





Click Here to Expand Forum to Full Width

Featured