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

BIN
main.o

Binary file not shown.

BIN
t

Binary file not shown.