Question: Homework: # 5 : Dynamic Sets Objects / Structures involved They are the same set involved in HM 4 . Student class studNode struct (

Homework: #5: Dynamic Sets
Objects / Structures involved
They are the same set involved in HM 4.
Student class
studNode struct (unsigned int, Student *)
SnEsa class (Orderable Array (HM1) of studNodes)
Usual ops: getNum, get, store, prepend, append, insert, remove
This homework will add 2 additional methods to the SnESA
class to create a Dynamic Set capability.
SnEsa* Sunion (const SnEsa *) const;// Inclusive OR
snEsa* Sintersect (const SnEsa *) const; // AND
Intersect: Unordered Set (C++ Code)
SnEsa* Sintersect (const SnEsa* B){ Put the intersect with B in C
int a = b = c =0;
studNode sb ={0, null}, sa ={0, null};
int bmax = BgetNum (); int amax = thisgetNum (); // Get Set sizes
int cmax =(bmax < amax)? bmax: amax; // Max size of new set = size of smaller set
SnEsa* C = new SnEsa (cmax); // Get ptr to SnEsa large enough to hold everything
for (a =0; a < amax; a++){// For each element in A (8000)
for (b =0; b < bmax; b++){// For each element in B (~2000 if match, 4000 if not)
if (((thisget(a)).id)==((Bget(b)).id)){// A[a]== B[b]
Cappend (thisget(a)); // Append ptr to matched studNode to set C
break; // Start testing with next A value
}
}// Either match found ... or not. Start next A element checks
}// All elements in Set A checked against all elements in Set B
return (C); Return ptr to set which is unordered intersection of A and B
}
Homework 5: Dynamic Set Unions
Implement the following function 2 ways:
SnEsa* Sunion (const SnEsa *) const; // Inclusive OR
1. Write the C++ code for the Union of 2 ordered sets (all
SnEsas studNode entries are ordered by studNode
UID), where the resulting SnEsa is an ordered set.
2. Write the C++ code for the Union of 2 unordered sets
(neither SnEsas studNode entries are ordered) where
the resulting SnEsa is an unordered set.

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 Programming Questions!