6.10 Lab*: Singly-Linked Lists (Park)

Replace Park.hDisplay() with output stream operator
This commit is contained in:
Iurii Tatishchev 2024-05-02 13:03:27 -07:00
parent ef6762ad57
commit 4ae56c5a42
Signed by: CaZzzer
GPG Key ID: 9A156B7DA6398968
3 changed files with 8 additions and 8 deletions

View File

@ -97,7 +97,7 @@ void LinkedList::displayList() const {
// While pCur points to a node, traverse the list.
while (pCur) {
// Display the value in this node.
pCur->park.hDdisplay();
cout << pCur->park << endl;
// Move to the next node.
pCur = pCur->next;

View File

@ -38,11 +38,12 @@ Park::Park(string cd, string st, string nm, string dsc, int yr) {
// Displays the values of a Park object member variables
// on one line (horizontal display)
// ***********************************************************
void Park::hDdisplay() const {
cout << code << " ";
cout << state << " ";
cout << year << " ";
cout << name << " " << endl;
ostream& operator<<(ostream &out, const Park &park) {
out << park.code << " ";
out << park.state << " ";
out << park.year << " ";
out << park.name << " ";
return out;
}
// ***********************************************************
@ -55,4 +56,3 @@ void Park::vDisplay() const {
cout << year << endl;
cout << state << endl;
}

View File

@ -56,7 +56,7 @@ public:
int getYear() const { return year; }
//other functions
void hDdisplay() const;
friend std::ostream &operator<<(std::ostream &, const Park &);
void vDisplay() const;
};