diff --git a/src/js/data-structures/circular-linked-list.js b/src/js/data-structures/circular-linked-list.js index 4209087a..865fcb70 100644 --- a/src/js/data-structures/circular-linked-list.js +++ b/src/js/data-structures/circular-linked-list.js @@ -32,7 +32,7 @@ export default class CircularLinkedList extends LinkedList { node.next = this.head; } else { node.next = current; - current = this.getElementAt(this.size()); + current = this.getElementAt(this.size() - 1); // update last element this.head = node; current.next = this.head; diff --git a/src/ts/data-structures/circular-linked-list.ts b/src/ts/data-structures/circular-linked-list.ts index f422d276..802f6138 100644 --- a/src/ts/data-structures/circular-linked-list.ts +++ b/src/ts/data-structures/circular-linked-list.ts @@ -36,7 +36,7 @@ export default class CircularLinkedList extends LinkedList { node.next = this.head; } else { node.next = current; - current = this.getElementAt(this.size()); + current = this.getElementAt(this.size() - 1); // update last element this.head = node; current.next = this.head;