In this module, I worked with C++ templated containers, iterators, and standard algorithms.
I implemented a function template called easyfind that searched for a specific integer within a given container. It returned the first occurrence or handled the absence of the element appropriately using exceptions.
I created a Span class to store a fixed number of integers and calculate the shortest and longest spans between them. For the shortest span, I made a copy of the object, sorted it, and then iterated over the sorted values, comparing neighboring elements to find the smallest difference. For the longest span, I used a similar approach but simply subtracted the first and last elements of the sorted container to determine the maximum distance.
I extended the std::stack
by creating a MutantStack class that allowed iteration over its elements.
Beneath the std::stack container lies the deque
container, which provides iterator support.
I solved the exercise by inheriting from std::stack and exposing the underlying deque’s iterators.