Singly linked node

Requirements

In this sub-project, you will implement the class Single_node.

A singly linked node contains two member variables: an element and a pointer to another singly linked node. Figure 1 shows a singly linked list which contains three nodes.

Figure 1. A singly linked list three nodes.

Class Specifications

UML Class Diagram

Single_node
- element:Type
- next_node:Single_node
+ create( in obj:Type = Type(), in n:Single_node = nullptr ):Single_node
+ retrieve():Type
+ next():Single_node


Description

A class which stores an object and a pointer to the next node in a linked list.

Member Variables

The two member variables are:

  • An Type, referred to as the element of the node, and
  • A pointer to a Single_node object, referred to as the next pointer.

Member Functions

Constructors

Single_node( Type const &, Single_node * )

This constructor takes two arguments: a constant reference to an Type (by default, a new instance of the type Type) and a pointer to a Single_node (by default nullptr). These are assigned to the member variables, respectively. (O(1))

Destructor

This class uses the default destructor.

Copy Constructor

This class uses the default copy constructor.

Accessors

This class has two accessors, one to get each of the two associated member variables:

Type retrieve() const
Returns the element of the node. (O(1))
Single_node *next() const
Returns the next pointer. (O(1))

Mutators

This class has no member functions which modify the member variables.

Friends

The classes Single_list<Type>, Cyclic_list<Type>, Sentinel_list<Type>, and Cyclic_sentinel_list<Type> are friends of this class.