diff --git a/pydatastructs/miscellaneous_data_structures/stack.py b/pydatastructs/miscellaneous_data_structures/stack.py index 2aa2feb..c25f914 100644 --- a/pydatastructs/miscellaneous_data_structures/stack.py +++ b/pydatastructs/miscellaneous_data_structures/stack.py @@ -150,7 +150,7 @@ class LinkedListStack(Stack): @property def peek(self): - return self.top.data + return self.top @property def top(self): @@ -164,4 +164,12 @@ class LinkedListStack(Stack): return self.stack.size def __str__(self): - return str(self.stack) + # Return items in bottom-to-top order like ArrayStack + items = [] + current = self.stack.head + while current: + items.append(current.data) + current = current.next + # Reverse to get bottom-to-top order + items.reverse() + return str(items) diff --git a/pydatastructs/miscellaneous_data_structures/tests/test_stack.py b/pydatastructs/miscellaneous_data_structures/tests/test_stack.py index ca8495d..6f2bdd1 100644 --- a/pydatastructs/miscellaneous_data_structures/tests/test_stack.py +++ b/pydatastructs/miscellaneous_data_structures/tests/test_stack.py @@ -51,4 +51,4 @@ def test_LinkedListStack(): peek = s.peek assert peek.data == s.pop().data - assert raises(TypeError, lambda: Stack(implementation='linked_list', items={0, 1})) + assert raises(TypeError, lambda: Stack(implementation='linked_list', items={0, 1})) \ No newline at end of file