Anonymous user
Doubly-linked list/Element insertion: Difference between revisions
Doubly-linked list/Element insertion (view source)
Revision as of 13:46, 14 September 2015
, 8 years agoAdded C++ solution
(Added C++ solution) |
|||
Line 180:
This function call changes the list from {a,b} to {a,b,c}.
=={{header|C++}}==
C++ already has own linked list structure. If we were to roll our own linked list, we could implement function inserting new value after specific node like that:
<lang cpp>template <typename T>
void insert_after(Node<T>* N, T&& data)
{
auto node = new Node<T>{N, N->next, std::forward(data)};
if(N->next != nullptr)
N->next->prev = node;
N->next = node;
}</lang>
=={{header|C sharp|C#}}==
|