954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

trying to find difference between 2 sets

I need to find the difference of 2 sets. below are my functions for the union and intersection of sets in my driver-file. Is the difference set a combination of the two?

IntegerSet IntegerSet::unionOfSets(IntegerSet b)
{
	IntegerSet c;

	for ( int i = 0; i < 101; i++ ) 
	{
		if ( set[i] || b.set[i] )
		c.set[i] = 1;
	}

	return( c );
}

IntegerSet IntegerSet::intersectionOfSets(IntegerSet b)
{
	IntegerSet d;
 
	for ( int i = 0; i < 101; i++ ) 
	{
		if ( set[i] && b.set[i] )
		d.set[i] = 1;
	}
 		return( d );
}
corby
Junior Poster
118 posts since Feb 2010
Reputation Points: 6
Solved Threads: 5
 

Are you having a problem you're not telling us or just asking a strange question that's hard to decipher?

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 
Are you having a problem you're not telling us or just asking a strange question that's hard to decipher?

im asking what the function would look like for the difference of sets

corby
Junior Poster
118 posts since Feb 2010
Reputation Points: 6
Solved Threads: 5
 

In your code:
The union uses OR
The intersection uses AND
I believe you'll find the difference uses XOR

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: