From 5494178412faa9b2e3c762c882c7c1c08475c328 Mon Sep 17 00:00:00 2001 From: coolguyinachair <73751559+coolguyinachair@users.noreply.github.com> Date: Sun, 3 Oct 2021 20:55:47 +0530 Subject: [PATCH] Update addAt() method Handle cases where addAt() is called with an index greater than the size of the linked list. --- .../algorithms/datastructures/linkedlist/DoublyLinkedList.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/python/algorithms/datastructures/linkedlist/DoublyLinkedList.py b/src/main/python/algorithms/datastructures/linkedlist/DoublyLinkedList.py index 4435927..dc6526f 100644 --- a/src/main/python/algorithms/datastructures/linkedlist/DoublyLinkedList.py +++ b/src/main/python/algorithms/datastructures/linkedlist/DoublyLinkedList.py @@ -112,6 +112,9 @@ def addAt(self, index, data): """ if index < 0: raise Exception('index should not be negative. The value of index was: {}'.format(index)) + + if index > self.llSize: + raise Exception('index is out of bounds. The value of index was: {}'.format(index)) if index == 0: self.addFirst(data)