Skip to content

Instantly share code, notes, and snippets.

@BogdanAriton
Created June 15, 2021 15:23
Show Gist options
  • Save BogdanAriton/b3435d714b226f8b5e45360830c28154 to your computer and use it in GitHub Desktop.
Save BogdanAriton/b3435d714b226f8b5e45360830c28154 to your computer and use it in GitHub Desktop.
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