Can someone help me with this problem? I'm having a hard time with it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class node 
{ 
public: 
int data() 
{
return data_field;  
} 
node* link() 
{
return link_field; 
} 
private: 
int data_field; 
node* link_field 
};




Suppose we are using the node class definition listed above. Your program is using a node* variable called head_ptr to point to the first node of a linked list (or head_ptr == NULL for the empty list). Write a few lines of C++ code that will print all the integers in the list.
Last edited on
That looks like a homework assignment, which part are you stuck with?

By the way assuming we have a pointer variable head_ptr, you need a while loop to print out the value of each node. When a value is printed out you should move on to the next node. Do not forget to check if the node is nullptr.
Topic archived. No new replies allowed.