can anyone help me to finish this. it is c++ class, and it is double linked list
ID: 3711876 • Letter: C
Question
can anyone help me to finish this. it is c++ class, and it is double linked list.
For the purposes of this lab, you will need to update the signature of displayList to be the following:
void displayList(ostream& out);
Similarly, you will also write displayNumberedList, with the following signature:
void displayNumberedList(ostream& out);
Now, when you call these functions, you can pass in cout or a file stream parameter to indicate whether the function should write to the console or to a file. For example:
L1.displayList(cout);
ofstream fout;
....
L2.displayList(fout);
this is my dispalyList function
template<class listdata>
void List<listdata>::displayList() const
{
Node* temp = start;
while (temp !=NULL)
{
cout<< temp->data<<" ";
temp = temp->next;
}
cout << endl;
}
Explanation / Answer
template<class listdata>
void List<listdata>::displayList(ostream& out) const
{
Node* temp = start;
// traverse the list until it ends
while (temp != NULL)
{
out<<temp->data<<" ";
// go to next node
temp = temp->next;
}
out<<endl;
}
template<class listdata>
void List<listdata>::displayNumberedList(ostream& out) const
{
Node* temp = start;
int i = 1;
// traverse the list until it ends
while (temp != NULL)
{
out<<i<<" "<<temp->data<<" ";
i++;
// go to next node
temp = temp->next;
}
out<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.