Brief Overview on Linked List
This documentation is written in a way to introduce the idea of a linked list
 
Loading...
Searching...
No Matches
Node Class Reference

Node Properties and Methods for the Linked List. More...

#include <node.hpp>

Public Member Functions

 Node (int const new_val)
 Constructor Creates a new node with an assigned value.
 
 Node (int const new_val, Node *const p_new_head)
 Constructor Creates a new node with an assigned value and an address pointing to the next head.
 
int getValue () const
 Method that will return the current value being stored in the node.
 
Node * get_nextNode () const
 Method that will return the address of the next node that the current node is pointing to.
 
void value (int const new_val)
 Method that will modify the value of the current node with the requested value.
 
void p_next (Node *const p_new_head)
 Method that will modify the address of the next node in the current node.
 

Detailed Description

Node Properties and Methods for the Linked List.

Constructor & Destructor Documentation

◆ Node() [1/2]

Node::Node ( int const new_val)

Constructor Creates a new node with an assigned value.

◆ Node() [2/2]

Node::Node ( int const new_val,
Node *const p_new_head )

Constructor Creates a new node with an assigned value and an address pointing to the next head.

Member Function Documentation

◆ get_nextNode()

Node * Node::get_nextNode ( ) const

Method that will return the address of the next node that the current node is pointing to.

Returns
The address of the next node store in the node as a constant.

Example

// Creating a Link Between Two Nodes
Node* p_tail_node = new Node( 4 );
Node* p_head_node = new Node( 4, p_tail_node );
std::cout << p_tail_node->get_nextNode() << std::endl;
std::cout << p_head_node->get_nextNode() << std::endl;
Node Properties and Methods for the Linked List.
Definition node.hpp:10
Node * get_nextNode() const
Method that will return the address of the next node that the current node is pointing to.
Definition node.cpp:22
Node(int const new_val)
Constructor Creates a new node with an assigned value.
Definition node.cpp:8

Output:

nullptr
<Address of p_tail_node>

◆ getValue()

int Node::getValue ( ) const

Method that will return the current value being stored in the node.

Returns
The value stored in the node as a constant.

Example

int my_val = 4;
Node* p_node = new Node( my_val );
std::cout << p_node->getValue() << std::endl;
int getValue() const
Method that will return the current value being stored in the node.
Definition node.cpp:18

Output:

4

◆ p_next()

void Node::p_next ( Node *const p_new_head)

Method that will modify the address of the next node in the current node.

Parameters
p_new_headA constant new address of the next node that we want to set to the node.
Returns
None

Example

Node* p_old_back_node = new Node( 5 );
std::cout << "Address of 'p_old_back_node': " << p_old_back_node << std::endl;
Node* p_front_node = new Node( 5, p_old_back_node );
std::cout << p_front_node->get_nextNode() << std::endl;
Node* p_new_back_node = new Node( 6 );
std::cout << "Address of 'p_new_back_node': " << p_new_back_node << std::endl;
// Changing the next node address
p_front_node->p_next( p_new_back_node );
std::cout << p_front_node->get_nextNode() << std::endl;
void p_next(Node *const p_new_head)
Method that will modify the address of the next node in the current node.
Definition node.cpp:31

Output:

Address of 'p_old_back_node': <address_of_p_back_node>
<address_of_p_back_node>
Address of 'p_new_back_node': <address_of_p_new_node>
<address_of_p_new_node>

◆ value()

void Node::value ( int const new_val)

Method that will modify the value of the current node with the requested value.

Parameters
new_valA constant integer value that we want to set to the node.
Returns
None

Example

Node* p_node = new Node( 4 );
std::cout << p_node->getValue() << std::endl;
p_node->value( 10 );
std::cout << p_node->getValue() << std::endl;
void value(int const new_val)
Method that will modify the value of the current node with the requested value.
Definition node.cpp:26

Output:

4
10

The documentation for this class was generated from the following files: