From 1fac2f09f218cac93339326392a8c1f74623f8ce Mon Sep 17 00:00:00 2001 From: mandolyte Date: Mon, 2 Jul 2018 10:14:29 -0400 Subject: [PATCH] fix to DoublyLinkedList.InsertFirst() --- DoublyLinkedList/DoublyLinkedList.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DoublyLinkedList/DoublyLinkedList.go b/DoublyLinkedList/DoublyLinkedList.go index e6e39f9..0d6ab6a 100644 --- a/DoublyLinkedList/DoublyLinkedList.go +++ b/DoublyLinkedList/DoublyLinkedList.go @@ -13,6 +13,11 @@ type LinkedList struct { func (list *LinkedList) InsertFirst(i int) { data := &Node{data: i} + if list.tail == nil { + list.head = data + list.tail = data + return + } if list.head != nil { list.head.prev = data data.next = list.head