fix average

v1
Brett 2023-02-16 00:06:36 -05:00
parent 08524cd280
commit fa8b67b6c9
1 changed files with 7 additions and 1 deletions

View File

@ -565,12 +565,14 @@ namespace blt {
private: private:
T* data = new T[Size]; T* data = new T[Size];
int index = 0; int index = 0;
int m_default = 0;
public: public:
averagizer_o_matic(): averagizer_o_matic(0) {} averagizer_o_matic(): averagizer_o_matic(0) {}
explicit averagizer_o_matic(T default_value){ explicit averagizer_o_matic(T default_value){
for (int i = 0; i < Size; i++){ for (int i = 0; i < Size; i++){
data[i] = default_value; data[i] = default_value;
} }
m_default = default_value;
} }
void insert(T t){ void insert(T t){
@ -581,10 +583,14 @@ namespace blt {
T average(){ T average(){
T total = 0; T total = 0;
int size = 0;
for (int i = 0; i < Size; i++){ for (int i = 0; i < Size; i++){
if (data[i] == m_default)
continue;
total += data[i]; total += data[i];
size++;
} }
return total / Size; return total / size;
} }
~averagizer_o_matic(){ ~averagizer_o_matic(){