📜  nodeafternode - C++ (1)

📅  最后修改于: 2023-12-03 15:17:57.572000             🧑  作者: Mango

NodeAfterNode - C++

NodeAfterNode is a C++ library for easily creating linked-lists. It provides a simple interface for adding and removing nodes, as well as iterating through the list.

Features
  • Simple and easy to use interface.
  • Efficient data structures for fast list traversal.
  • Supports custom node types.
  • Safe memory management.
  • Header-only library.
Installation

NodeAfterNode is a header-only library, meaning that all you need to do is include the header file in your project.

#include "nodeafternode.hpp"
Quick Start

Create a new list:

na::NodeAfterNode<int> list;

Add new nodes:

list.append(1);
list.append(2);
list.append(3);

Iterate through the list:

for (auto it = list.begin(); it != list.end(); ++it) {
    std::cout << *it << " ";
}
std::cout << std::endl;

Output:

1 2 3

Remove nodes:

list.remove(2);
Custom Node Types

NodeAfterNode supports custom node types. Simply create a struct or class that contains a value member and derives from na::Node.

struct CustomNode : public na::Node<CustomNode> {
    int value;

    CustomNode(int value) : value(value) {}
};

Then create the list with the custom node type:

na::NodeAfterNode<CustomNode> list;

And add new nodes:

list.append(new CustomNode(1));
list.append(new CustomNode(2));
list.append(new CustomNode(3));
Memory Management

NodeAfterNode takes care of deallocating memory when nodes are removed from the list. However, if you are creating custom node types, you are responsible for deallocating the memory taken up by those nodes.

Conclusion

NodeAfterNode is a simple and efficient linked-list library for C++. It provides a simple interface for creating and manipulating lists, and supports custom node types for added flexibility.