snippets 0.1.0
Loading...
Searching...
No Matches
hsc_snippets::DominantTracker Class Reference

#include <dominant_tracker.hpp>

Public Member Functions

 DominantTracker ()
 
void add (int value)
 
std::optional< int > getDominant () const
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DominantTracker()

hsc_snippets::DominantTracker::DominantTracker ( )
inline

Constructor initializes an empty tracker with no elements.

Member Function Documentation

◆ 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
valueThe 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: