Мне было дано следующее заявление моего профессора, и у меня есть пара функций, которые мне нужно написать на основе этого объявления LinkedList, но я застрял в определении того, что делает пара строк кода. я понимаю все в значительной степени до этих строк;может кто-нибудь объяснить, что делает эта строка кода? Речь идет о связанных списках
friend ostream& operator<<(ostream& os, const LinkedList &ll)
{
LinkedList::Node *current;
for (current = ll.head; current != NULL; current = current->next)
os << current->data << " ";
return os;
}
вот полный код.
#include <iostream>
#include <cstdlib>
using namespace std;
class LinkedList
{
public:
LinkedList() { head = NULL; } // default constructor makes an empty list
// functions to aid in debugging
// -----------------------------
friend ostream& operator<<(ostream& os, const LinkedList &ll);
void insertHead(int item);
private:
class Node // inner class for a linked list node
{
public:
Node(int item, Node *n) // constructor
int data; // the data item in a node
Node *next; // a pointer to the next node in the list
};
Node *head; // the head of the list
};
friend ostream& operator<<(ostream& os, const LinkedList &ll)
{
LinkedList::Node *current;
for (current = ll.head; current != NULL; current = current->next)
os << current->data << " ";
return os;
}
void LinkedList::insertHead(int item) // insert at head of list
{
head = new Node(item, head);
}
LinkedList::Node::Node(int item, Node *n) {Node::data = item; next = n;}
пс. может кто-то также объяснить, что делает оператор содружества, потому что я никогда не использовал его раньше?
[Google] (http://www.google.com/) является вашим другом! – 0x499602D2