6.10 Lab*: Singly-Linked Lists (Park)
Replace Park.hDisplay() with output stream operator
This commit is contained in:
parent
ef6762ad57
commit
4ae56c5a42
@ -97,7 +97,7 @@ void LinkedList::displayList() const {
|
|||||||
// While pCur points to a node, traverse the list.
|
// While pCur points to a node, traverse the list.
|
||||||
while (pCur) {
|
while (pCur) {
|
||||||
// Display the value in this node.
|
// Display the value in this node.
|
||||||
pCur->park.hDdisplay();
|
cout << pCur->park << endl;
|
||||||
|
|
||||||
// Move to the next node.
|
// Move to the next node.
|
||||||
pCur = pCur->next;
|
pCur = pCur->next;
|
||||||
|
@ -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
|
// Displays the values of a Park object member variables
|
||||||
// on one line (horizontal display)
|
// on one line (horizontal display)
|
||||||
// ***********************************************************
|
// ***********************************************************
|
||||||
void Park::hDdisplay() const {
|
ostream& operator<<(ostream &out, const Park &park) {
|
||||||
cout << code << " ";
|
out << park.code << " ";
|
||||||
cout << state << " ";
|
out << park.state << " ";
|
||||||
cout << year << " ";
|
out << park.year << " ";
|
||||||
cout << name << " " << endl;
|
out << park.name << " ";
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***********************************************************
|
// ***********************************************************
|
||||||
@ -55,4 +56,3 @@ void Park::vDisplay() const {
|
|||||||
cout << year << endl;
|
cout << year << endl;
|
||||||
cout << state << endl;
|
cout << state << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
int getYear() const { return year; }
|
int getYear() const { return year; }
|
||||||
|
|
||||||
//other functions
|
//other functions
|
||||||
void hDdisplay() const;
|
friend std::ostream &operator<<(std::ostream &, const Park &);
|
||||||
|
|
||||||
void vDisplay() const;
|
void vDisplay() const;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user