The node is the basic building block of many data structures which we will discuss in this book. Node has two functions. Its first function is that it holds a piece of data, also known as the Value of node. The second function is its connectivity between another node and itself, using an object reference pointer, also known as the Next pointer. Based on this explanation, we can create a Node data type in C++, as follows:
class Node
{
public:
int Value;
Node * Next;
};
We will also use the following diagram to represent a single node:
Now, let's create three single nodes using our new Node data type. The nodes will contain the values 7, 14, and 21 for each node. The code should be as follows:
Node * node1 = new Node;
node1->Value = 7;
Node * node2 = new Node;
node2->Value = 14;
Node * node3 = new Node;
node3->Value = 21;
Note...