From a536c5b731ba8b8b4912f61681e711007b977f24 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sun, 26 May 2024 00:36:46 +0200 Subject: [PATCH] Double Linked List: insert_at --- src/list.cr | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/list.cr b/src/list.cr index b5801b9..e57b9c9 100644 --- a/src/list.cr +++ b/src/list.cr @@ -128,9 +128,12 @@ class DoubleLinkedList(V) i += 1 end - new_node.next = current.next - current.next = new_node - new_node.previous = current + new_node.next = current + new_node.previous = current.previous + + current.previous.not_nil!.next = new_node + current.previous = new_node + @size += 1 new_node end