Created
June 15, 2021 15:23
-
-
Save BogdanAriton/b3435d714b226f8b5e45360830c28154 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
LinkedList(std::initializer_list<Data> listOfItems) noexcept | |
{ | |
if (listOfItems.size() != 0) | |
{ | |
auto it = listOfItems.begin(); // will use the iterator for the list to get the first element | |
head = std::make_unique<Node>(*it); // The head is our first element | |
size++; // added first item | |
Node *current = head.get(); | |
++it; | |
for (; it != listOfItems.end(); ++it) // we traverse the list using the defined iterator | |
{ | |
current->next = std::make_unique<Node>(*it); | |
current = current->next.get(); | |
size++; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment