From df8a0f205faf36db8afdafdfc56375e49054ac18 Mon Sep 17 00:00:00 2001 From: SleepiCaffeine Date: Tue, 20 Jun 2023 18:47:32 +0300 Subject: [PATCH] Updated the node class --- Data Structures/{node.h => node.hpp} | 235 +++++++++++++-------------- 1 file changed, 117 insertions(+), 118 deletions(-) rename Data Structures/{node.h => node.hpp} (86%) diff --git a/Data Structures/node.h b/Data Structures/node.hpp similarity index 86% rename from Data Structures/node.h rename to Data Structures/node.hpp index 4238c0b..160d2c9 100644 --- a/Data Structures/node.h +++ b/Data Structures/node.hpp @@ -1,119 +1,118 @@ -/** - * @file node.h - * @author Vakaris Michejenko (sleepicaffeine@gmail.com) - * @brief A header that defines a dynamic Node class - * @version 0.2 - * @date 2023-06-19 - * @copyright Copyright (c) 2023 - * @link https://github.com/SleepiCaffeine - */ - -#ifndef NODE_H -#define NODE_H -/*! - * @class Node - * @brief Node class. - * - * @details A standard Node data structure that is used as a base unit in many other data structures. Supports insertion, removal, and dynamic types. - * - * @fn get_data() - * @fn set_data(T dt) - * @fn get_next() - * @fn set_next(Node* nd) - * @fn forward() - * @tparam T typename - */ -template -class node { -private: - node* next; /**< Pointer to the next Node*/ - T data; /**< Data which is stored in the Node*/ - -public: - /** - * Creates a new node that points to NULL both ways, but has NULL data. - * @brief Default constructor. - */ - node() - : next{nullptr}, data{} { } - - /** - * Creates a new node that points to NULL both ways, and has data. - * @brief Constructor. - * @param dt node data. - */ - node(const T dt) - : next{nullptr}, data{dt} { } - - /** - * Creates a new node that points to a node forward, but not backward, and has data. - * @brief Constructor. - * @param nd node to which it will point. - * @param dt node data. - */ - node(node* const nd, const T dt) - : next{nd}, data{dt} { } - - /** - * Creates a new node that points to a node in both ways, and has data. - * @brief Constructor. - * @param nnd node to which it points to next. - * @param pnd node to which it points to behind. - * @param dt node data. - */ - node(node* const nnd, node* const pnd, const T dt) - : next{nnd}, data{dt} { } - - /** - * Construct a new node from another node object. - * @brief Copy constructor. - * @param nd node to copy from. - */ - node(const node& nd) - : next{nd.next}, data{nd.data} { } - - - /** - * @brief Get the node's data. - * @return node data. - */ - T get_data() const { - return this->data; - } - - /** - * @brief Set the current node's data. - * @param dt new node data. - */ - void set_data(const T dt) { - this->data = dt; - } - - /** - * @brief Get the pointer to the next node. - * @return node object to which the current node object points to next. - */ - node* get_next() const { - return this->next; - } - - /** - * @brief Set the pointer to the next node. - * @param nd new node object to which the current node object will point to next. - */ - void set_next(node* const nd) { - this->next = nd; - } - - /** - * @brief Set current node to the next node. - */ - void forward() { - if (this->next) { - this->data = next->get_data(); - this->next = next->get_next(); - } - } -}; - +/** + * @file node.h + * @author Vakaris Michejenko (sleepicaffeine@gmail.com) + * @brief A header that defines a dynamic node class + * @version 0.2 + * @date 2023-06-19 + * @copyright Copyright (c) 2023 + * @link https://github.com/SleepiCaffeine + */ + +#ifndef NODE_H +#define NODE_H +/*! + * @class Node + * @brief Node class. + * + * @details A standard Node data structure that is used as a base unit in many other data structures. Supports insertion, removal, and dynamic types. + * + * @fn get_data() + * @fn set_data(T dt) + * @fn get_next() + * @fn set_next(Node* nd) + * @fn forward() + * @tparam T typename + */ +template +class node { +private: + node* next; /**< Pointer to the next node [node*]*/ + T data; /**< Data which is stored in the Node [T]*/ + +public: + /** + * Creates a new node that points to NULL both ways, but has NULL data. + * @brief Default constructor. + */ + node() + : next{nullptr}, data{} { } + + /** + * Creates a new node that points to NULL both ways, and has data. + * @brief Constructor. + * @param dt node data. + */ + node(const T dt) + : next{nullptr}, data{dt} { } + + /** + * Creates a new node that points to a node forward, but not backward, and has data. + * @brief Constructor. + * @param nd node to which it will point. + * @param dt node data. + */ + node(node* const nd, const T dt) + : next{nd}, data{dt} { } + + /** + * Creates a new node that points to a node in both ways, and has data. + * @brief Constructor. + * @param nnd node to which it points to next. + * @param dt node data. + */ + node(node* const nnd, node*, const T dt) + : next{nnd}, data{dt} { } + + /** + * Construct a new node from another node object. + * @brief Copy constructor. + * @param nd node to copy from. + */ + node(const node& nd) + : next{nd.next}, data{nd.data} { } + + + /** + * @brief Get the node's data. + * @return node data. + */ + T get_data() const { + return this->data; + } + + /** + * @brief Set the current node's data. + * @param dt new node data. + */ + void set_data(const T dt) { + this->data = dt; + } + + /** + * @brief Get the pointer to the next node. + * @return node object to which the current node object points to next. + */ + node* get_next() const { + return this->next; + } + + /** + * @brief Set the pointer to the next node. + * @param nd new node object to which the current node object will point to next. + */ + void set_next(node* const nd) { + this->next = nd; + } + + /** + * @brief Set current node to the next node. + */ + void forward() { + if (this->next) { + this->data = next->get_data(); + this->next = next->get_next(); + } + } +}; + #endif // NODE_H \ No newline at end of file