📅  最后修改于: 2023-12-03 15:17:57.572000             🧑  作者: Mango
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.
NodeAfterNode is a header-only library, meaning that all you need to do is include the header file in your project.
#include "nodeafternode.hpp"
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);
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));
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.
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.