#include <dominant_tracker.hpp>
The DominantTracker class is designed to track elements added to it and determine the most frequently occurring element (the dominant element). The dominant element is defined as an element whose frequency is more than half the size of all elements added.
◆ DominantTracker()
hsc_snippets::DominantTracker::DominantTracker |
( |
| ) |
|
|
inline |
Constructor initializes an empty tracker with no elements.
◆ add()
void hsc_snippets::DominantTracker::add |
( |
int | value | ) |
|
|
inline |
Adds a new element to the tracker and updates the most frequent element if necessary.
- Parameters
-
value | The element to be added to the tracker. |
◆ getDominant()
std::optional< int > hsc_snippets::DominantTracker::getDominant |
( |
| ) |
const |
|
inline |
Returns the current dominant element if it exists. A dominant element is defined as an element whose frequency is more than half the size of all elements added. If no such element exists or no elements have been added, returns std::nullopt.
- Returns
- An optional containing the dominant element if it exists, otherwise std::nullopt.
The documentation for this class was generated from the following file: