Question: You are to use doubly linked lists to implement mathematical sets. Note that in a set each element is unique.Write the below functions, insert: Inserts

You are to use doubly linked lists to implement mathematical sets. Note that in a set each element is unique.Write the below functions,

  1. insert: Inserts a new node with a newValue if it does not exist in the list (set). Returns true if the insertion is successful, else false.

template

bool insertSet(DoubleNode*& head, Object newValue);

  1. setUnion: Returns a pointer to a newly created list (set) that is the union of two lists: head1 and head2. The union contains all elements that are either in list1 or in list2.

template

DoubleNode* setUnion(DoubleNode* head1,DoubleNode* head2);

  1. setIntersection: Returns a pointer to newly created list (set) that is the intersection of two lists (sets): head1 and head2. The intersection containing all elements that are both in list1 and in list2.

template

DoubleNode* setIntersection(DoubleNode* head1,DoubleNode* head2);

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!