-
Again, list traversal by linear search algorithm:
#include <iostream>
using namespace std;
// Node.h
class Node {
friend void print_list( Node const& head );
Node* pnext;
public:
int data;
// ...
};
// Print contents of the list:
void print_list( Node const& head )
{
cout << '[' << head.size() << "] ";
Node const* iter = &head;
do {
cout << iter->data << ' ';
iter = iter->pnext;
} while ( iter != NULL );
cout << '\n';
}
|
|