Thread: union of two arrays

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    8

    union of two arrays

    could any one help me to find the union of two sets.The process i did is that first i made two arrays and cancatenated the first array to the next array and compared each elements with all the other elemensts of the array.
    oops i cannot get the output.help me

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    That's pretty much what you have to do unless your sets are sorted.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    What set primitives have you written?

    Like for example
    AddSet( set, element );
    IsMemberOf( set, element );
    The external interface (which is set-based) should not care about the underlying implementation (which is array based)

    Union pseudo-code is just
    Code:
    set Union ( set a, set b ) {
      result = a;
      foreach i member of b
        if not IsMemberOf( result, i ) AddSet( result, i );
    }
    So post some examples of what you have done by way of a set API
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. Union 2 arrays
    By sugie in forum C++ Programming
    Replies: 2
    Last Post: 10-20-2005, 10:51 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM
  5. Sorting a Union
    By andy in forum C Programming
    Replies: 4
    Last Post: 11-21-2001, 10:12 AM