From 9742eee388b535530a334d1a9ed5892918333b9e Mon Sep 17 00:00:00 2001 From: psquared-dev <32394996+psquared-dev@users.noreply.github.com> Date: Tue, 4 Apr 2023 05:31:23 +0530 Subject: [PATCH] Update peek() method to read from tail. Peeking at the element should be done from the tail rather than the head. --- src/data-structures/stack/Stack.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data-structures/stack/Stack.js b/src/data-structures/stack/Stack.js index 8d061412..fed8a55c 100644 --- a/src/data-structures/stack/Stack.js +++ b/src/data-structures/stack/Stack.js @@ -26,7 +26,7 @@ export default class Stack { } // Just read the value from the start of linked list without deleting it. - return this.linkedList.head.value; + return this.linkedList.tail.value; } /**