Doubly-linked list/Element insertion: Difference between revisions
Content added Content deleted
(Added C++ solution) |
|||
Line 180: | Line 180: | ||
This function call changes the list from {a,b} to {a,b,c}. |
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#}}== |
=={{header|C sharp|C#}}== |