printStatesByCondition
This commit is contained in:
1 file changed
+27
-5
@@ -401,6 +401,10 @@ public:
|
|||||||
// geters
|
// geters
|
||||||
string getName() const { return name; }
|
string getName() const { return name; }
|
||||||
double getArea() const { return area; }
|
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();
|
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() {
|
int main() {
|
||||||
DoublyLinkedStack<int> stack;
|
DoublyLinkedStack<int> stack;
|
||||||
|
|
||||||
@@ -516,8 +534,14 @@ int main() {
|
|||||||
//cout << "Removing state:" << endl;
|
//cout << "Removing state:" << endl;
|
||||||
//cout << stateList.removeState() << endl;
|
//cout << stateList.removeState() << endl;
|
||||||
|
|
||||||
cout << "States with area between 2000 and 3000:" << endl;
|
cout << "States with area between 9800500 and 9987263:" << endl;
|
||||||
states.printStatesByArea(2000, 3000);
|
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");
|
State* foundState = states.findStateByName("USA");
|
||||||
if (foundState) {
|
if (foundState) {
|
||||||
@@ -536,9 +560,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cout << "States after removal:" << endl;
|
cout << "States after removal:" << endl;
|
||||||
states.printStatesByArea(0, 10000);
|
states.printStatesByArea(0, 10000000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user