printStatesByCondition
This commit is contained in:
parent
6584ce5f92
commit
256a939081
32
pr6.cpp
32
pr6.cpp
@ -401,6 +401,10 @@ public:
|
||||
// geters
|
||||
string getName() const { return name; }
|
||||
double getArea() const { return area; }
|
||||
long getPopulation() const { return population; }
|
||||
string getCapital() const { return capital; }
|
||||
string getLanguage() const { return language; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -449,8 +453,22 @@ public:
|
||||
current = current->getNext();
|
||||
}
|
||||
}
|
||||
|
||||
// Универсальная фильтрация государств по произвольному условию
|
||||
void printStatesByCondition(function<bool(const State&)> condition) {
|
||||
Element<State>* current = stateList.getHead();
|
||||
while (current != nullptr) {
|
||||
const State& state = current->getInfo();
|
||||
if (condition(state)) {
|
||||
cout << state << endl;
|
||||
}
|
||||
current = current->getNext();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
DoublyLinkedStack<int> stack;
|
||||
|
||||
@ -516,8 +534,14 @@ int main() {
|
||||
//cout << "Removing state:" << endl;
|
||||
//cout << stateList.removeState() << endl;
|
||||
|
||||
cout << "States with area between 2000 and 3000:" << endl;
|
||||
states.printStatesByArea(2000, 3000);
|
||||
cout << "States with area between 9800500 and 9987263:" << endl;
|
||||
states.printStatesByArea(9800500, 9987263);
|
||||
|
||||
cout << "States with population greater than 1 billion:" << endl;
|
||||
states.printStatesByCondition([](const State& state)
|
||||
{
|
||||
return state.getPopulation() > 1000000000;
|
||||
});
|
||||
|
||||
State* foundState = states.findStateByName("USA");
|
||||
if (foundState) {
|
||||
@ -536,9 +560,7 @@ int main() {
|
||||
}
|
||||
|
||||
cout << "States after removal:" << endl;
|
||||
states.printStatesByArea(0, 10000);
|
||||
|
||||
|
||||
states.printStatesByArea(0, 10000000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user