Skip to content

Instantly share code, notes, and snippets.

@BogdanAriton
Created June 15, 2021 15:16
Show Gist options
  • Save BogdanAriton/8ff8e3d8b5a8c285bac375efbd76d810 to your computer and use it in GitHub Desktop.
Save BogdanAriton/8ff8e3d8b5a8c285bac375efbd76d810 to your computer and use it in GitHub Desktop.
template <typename Data>
class LinkedList
{
private:
// the node holds only the data we want to store
// and the link to the next node in the list
struct Node
{
using node_ptr = std::unique_ptr<Node>;
Data data{};
node_ptr next = nullptr;
};
using node_ptr = std::unique_ptr<Node>;
// we always need to know where the link starts, thus we need a head node
node_ptr head = nullptr;
// we also need to keep track of how many numbers are in the list
std::size_t size = 0;
public:
...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment