1
0

remove first zero

This commit is contained in:
Captain ALM 2022-10-28 10:37:23 +01:00
parent 34044faf99
commit 22e18284ff
3 changed files with 14 additions and 17 deletions

View File

@ -21,20 +21,20 @@ int prompti(string,bool*);
double promptd(string,bool*);
double avgitr(std::list<double>*);
double avgfor(std::list<double>*);
int maximum(std::vector<int>&);
int maximum(std::list<int>&);
void delzrfrst(std::list<double>&);
int main() {
printlm("Largest:");
printlm("Remove first zero from:");
bool s {};
std::list<int> lst {};
std::list<double> lst {};
do {
auto v = prompti("Enter a integer value: ", &s);
auto v = promptd("Enter a double value: ", &s);
if (s) lst.push_back(v);
} while (s);
printm("Maximum: ");
printlm(maximum(lst));
printlm("First zero removed:");
delzrfrst(lst);
for (const auto c : lst) printlm(c);
return 0;
}
@ -76,14 +76,11 @@ double avgfor(std::list<double> *values) {
return sum / values->size();
}
int maximum(std::vector<int> &values) {
int m {};
for (const auto c : values) if (c > m) m = c;
return m;
}
int maximum(std::list<int> &values) {
int m {};
for (const auto c : values) if (c > m) m = c;
return m;
void delzrfrst(std::list<double> &values) {
for (auto itr {values.cbegin()}; itr != values.cend(); ++itr) {
if (*itr == 0) {
itr = values.erase(itr);
break;
}
}
}

BIN
main.o

Binary file not shown.

BIN
t

Binary file not shown.