fix StatesStack inheritance with DoublyLinkedStack; remove getStateListHead() and use getHead(); overridden output operator (operator<<) for the StateList class;
This commit is contained in:
1 file changed
+9
-12
@@ -415,7 +415,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class StateList {
|
class StateList : public DoublyLinkedStack<State> {
|
||||||
protected:
|
protected:
|
||||||
SinglyLinkedListQueue<State> stateList;
|
SinglyLinkedListQueue<State> stateList;
|
||||||
|
|
||||||
@@ -424,8 +424,13 @@ public:
|
|||||||
void addState(const State& state) {
|
void addState(const State& state) {
|
||||||
stateList.push(state);
|
stateList.push(state);
|
||||||
}
|
}
|
||||||
Element<State>* getStateListHead() const {
|
friend ostream& operator<<(ostream& os, const StateList& stateList) {
|
||||||
return stateList.getHead();
|
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 << "List of states:" << endl;
|
||||||
//cout << states->findStateByName("USA") << endl;
|
//cout << states->findStateByName("USA") << endl;
|
||||||
Element<State>* current = states->getStateListHead();
|
cout << loadedStates << endl;
|
||||||
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 << "States with area between 9800500 and 9987263:" << endl;
|
cout << "States with area between 9800500 and 9987263:" << endl;
|
||||||
states->printStatesByArea(9800500, 9987263);
|
states->printStatesByArea(9800500, 9987263);
|
||||||
|
|||||||
Reference in new issue
Block a user