Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

All the questions need to be completed The class should be made in c++ Create a

ID: 3821449 • Letter: A

Question

All the questions need to be completed The class should be made in c++ Create a C++ class similar to STL maps. Here are the requirements your class must meet: 1. The class should be called Map. (Notice the capital M.) 2. It should be implemented using binary search trees. CThat's plain binary search trees, not red-black trees.) 3. The class should be generic. Keys should be any type that supports the operator. Elements should be any type that supports value initialization 4. The class should provide the following operations: default constructor, copy constructor, destructor, indexing operator, s empty, begin erase (key), erase (iterator), clear, swap. The end, find copy constructor should perform a deep copy and the destructor should deallocate all the memory dynamically allocated by the map 5. The class should provide iterators that support the following operations: The operator should return a ref default constructor, erence to an STL object of class pair. The class Map should include the type iterator. (The class only needs to provide non-constant iterators. It does not need to provide constant or reverse iterators.) 6. All the Map and iterator operations should be implemented as efficiently as plain binary search trees will allow Consult Chap. 8 of the CS142 notes and possibly also a reference such as cppreference.com for more information on the above operations. (Links on the main page of the course web site.) Most of the algorithms you need to implement these operations are described in pseudocode in Chap. 6 of the (CS344) notes. You may also find it useful to review the implementation of vectors and linked lists in Chap. 11 and 12 of the CS142 notes I strongly suggest you implement your class very gradually, adding one op- eration at a time as much as possible. As was the case for the first project, the assignment policy available on the course web site applies to this project with one exception: if you do the project as a team, you are allowed to divide the work with your teammates. In that case, the implementation work should be divided evenly between all the team members

Explanation / Answer

#include <iostream>
#include <map>

int main ()
{
std::map<char,int> mymap;


mymap.insert ( std::pair<char,int>('a',100) );
mymap.insert ( std::pair<char,int>('z',200) );

std::pair<std::map<char,int>::iterator,bool> ret;
ret = mymap.insert ( std::pair<char,int>('z',500) );
if (ret.second==false) {
std::cout << "xxxxxxxxxxxxxxxxxxxxx";
std::cout << " xxxxxxxxx " << ret.first->second << ' ';
}

  
std::map<char,int>::iterator it = mymap.begin();
mymap.insert (it, std::pair<char,int>('b',300));   
mymap.insert (it, std::pair<char,int>('c',400));

std::map<char,int> anothermap;
anothermap.insert(mymap.begin(),mymap.find('c'));

  
std::cout << "mymap contains: ";
for (it=mymap.begin(); it!=mymap.end(); ++it)
std::cout << it->first << " => " << it->second << ' ';

std::cout << "anothermap contains: ";
for (it=anothermap.begin(); it!=anothermap.end(); ++it)
std::cout << it->first << " => " << it->second << ' ';

return 0;
}