Union of a set

This is a discussion on Union of a set within the C Programming forums, part of the General Programming Boards category; I got the intersection of a set finally working but I can not make the Union of a set work. ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    12

    Union of a set

    I got the intersection of a set finally working but I can not make the Union of a set work. Basicly I need to get the union of 7 sets. For example:

    1234
    456
    789
    1456
    812
    367
    13467

    Now am doing this with a big string where I store the 7 sets but I just can't find the logic to compare each of them and only add the new one. Now I have to do this with simple code, meaning I have to make the functions myself and I can't use any functions from libraries. Please give me some help here with the logic behind this.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Give it your best shot... then if you run into troubles post the failed code and let people comment. We don't write code... we criticise it.

    C Board - Announcements in Forum : General Programming Boards

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    12
    Well I tried again but still not working like it should:
    Last edited by bman900; 11-08-2010 at 12:30 AM.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    12
    WOW I GOT IT! Turns out I was overwriting the compare set instead of adding to it, with a few adjustments I got it! And here is the code if u want to check for any mistakes:
    Last edited by bman900; 11-08-2010 at 12:29 AM.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    First of all... that code won't compile.

    C can't process any function or variable it hasn't already seen, reading from the top of the page. Thus you either need to move your functions above main or post prototypes above main.

    Your bracketing is also wrong... you need to pair them off, as you have more closes than opens.

    Fix it up a bit, try compiling it and see what happens... then post updated code (do not edit what is already there) with the error messages you're getting.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    12
    Well I took that code and implemented into the project it was suppose to go into where the intersection and the union of sets are calculated. Now I did clean this code up as well and complied fine and worked just like i wanted it to. Here it is:
    Last edited by bman900; 11-08-2010 at 12:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-19-2007, 08:10 AM
  2. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  3. Set default directory with GetTempDir?
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 05-04-2003, 11:36 PM
  4. Sorting a Union
    By andy in forum C Programming
    Replies: 4
    Last Post: 11-21-2001, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21