Question: PRACTICE PROBLEM #1 (DIFFICULTY LEVEL = EASY) Write a method named Complement for the Array of Booleans implementation of the Set ADT that takes a

PRACTICE PROBLEM #1 (DIFFICULTY LEVEL = EASY) Write a method named Complement for the Array of Booleans implementation of the Set ADT that takes a Set s1 as input. This method should store in the owning object the elements that were not in s1 Follow-On Thought Exercise: Why would we not be able to write this Complement( ) method for our Array of Integers implementation?

existing code (array of booleans):

bool Set::isMember (int element){

if (element = MAX)

{

cout

return false;

}

else

{

return elements[element];

}

}

void Set:: computeIntersection(Set a, Set b)

for (int i = 0; i

if(a.elements[i]==true && b.elements[i]==true){

elements[i] = true;

}

else{

elements[i] = false;

}

}

void Set::display()

for(int i = 0; i

{

if(elements[i] == true)

{

cout

}

}

PRACTICE PROBLEM #1 (DIFFICULTY LEVEL = EASY) Write a method named Complement

THREE APPROACHES TO BUILDING A DATA STRUCTURE FOR A SET . Assume we are interested in sets over the universe 0 through 24 Suppose our set current has the value ( 1,4, 12) Approach #1-An Array of Booleans ("BitVector") 0 12 3 4 5 6 7 8 9 10 1112 13 14 15 16 1718 19 20 21 22 23 24 ty'.' Approach #2-An Array of Integers create a for loop to do this 0 1 2 3 4 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 .. Approach #3-A " Chain" of Objects (will learn about later) "Leader" Object 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!