Question: Outline: in this assignment you will implement both the Map and the Unordered Map abstract data types using a self - balancing BST and a
Outline: in this assignment you will implement both the Map and the Unordered Map abstract data types
using a selfbalancing BST and a hash table respectively as the underlying data structures. You will then use your maps to
solve some wellknown programming problems
maps are associative containers that store elements formed by a combination of key type and
mapped type. The keys are used to sort and uniquely identify the elements, while the values store the content associated to
the key. The map has the following properties:
Associative elements in the container are referenced by their key and not by their absolute position in the
container.
Ordered elements in the container follow a strict order at all times.
Unique keys no two elements in the container can have equivalent keys.
Implement a map ADT using a selfbalancing BST AVL or redblack tree as the underlying data structure. In addition to the big
it must support the following operations: where valuetype is a pair
mappedtype& operatorconst keytype& k;
o if k matches the key of an element in the container, return a reference to its mapped value. If k does not
match the key of an element in the container, insert a new element with key k and value constructed using
the default constructor of mappedtype and return that instead.
iterator insertiterator position, const valuetype& val;
o insert val into map at position. If the key already exists, return an iterator to that preexisting element.
Must also verify that the insert operation does not violate the order property of the map.
void eraseiterator position;
o remove from map element at iterator position and rebalance the underlying tree.
void eraseiterator first, iterator last;
o remove from map a range of elements between first and last and rebalance the underlying tree.
void clear;
o remove and destroy all elements from map
iterator findconst keytype& k;
o search container for element with key equivalent to k return an iterator to that element if found otherwise an
iterator to map::end.
bool empty const;
o return true if map is empty.
int size const;
o return number of elements in map container.
int maxsize const;
o return max number of elements map can hold
iterator findMin; and iterator findMax; selfexplanatory
Must also provide an iterator inner class that provides the following methods with the expected behaviour:
begin
end
increment
dereference
Your iterator must support an infix traversal of the tree it should print out a sorted list when used in a rangebased for loop
Page section of the Weiss textbook gives some hints on how to go about creating a BST iterator.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
