Created
June 15, 2021 15:16
-
-
Save BogdanAriton/8ff8e3d8b5a8c285bac375efbd76d810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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