remove first zero
This commit is contained in:
parent
34044faf99
commit
22e18284ff
31
main.cpp
31
main.cpp
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user