fix StatesStack inheritance with DoublyLinkedStack; remove getStateListHead() and use getHead(); overridden output operator (operator<<) for the StateList class;

This commit is contained in:
gandc 2024-05-23 03:32:51 +03:00
parent 38c584323c
commit 5cdcca7290
Signed by: gandc
GPG Key ID: 9F77B03D43C42CB4

21
pr6.cpp
View File

@ -415,7 +415,7 @@ public:
};
class StateList {
class StateList : public DoublyLinkedStack<State> {
protected:
SinglyLinkedListQueue<State> stateList;
@ -424,8 +424,13 @@ public:
void addState(const State& state) {
stateList.push(state);
}
Element<State>* getStateListHead() const {
return stateList.getHead();
friend ostream& operator<<(ostream& os, const StateList& stateList) {
Element<State>* current = stateList.stateList.getHead();
while (current != nullptr) {
os << current->getInfo() << endl;
current = current->getNext();
}
return os;
}
// Удаление государства из начала списка
@ -595,15 +600,7 @@ int main() {
cout << "List of states:" << endl;
//cout << states->findStateByName("USA") << endl;
Element<State>* current = states->getStateListHead();
while (current != nullptr) {
if (current->getInfo().getName() != "") {
cout << "State: " << current->getInfo().getName() << ", Capital: " << current->getInfo().getCapital()
<< ", Language: " << current->getInfo().getLanguage() << ", Population: " << current->getInfo().getPopulation()
<< ", Area: " << current->getInfo().getArea() << endl;
}
current = current->getNext();
}
cout << loadedStates << endl;
cout << "States with area between 9800500 and 9987263:" << endl;
states->printStatesByArea(9800500, 9987263);