added __len__
This commit is contained in:
@@ -21,7 +21,7 @@ class Stack[T]:
|
|||||||
|
|
||||||
''' initializes an empty stack '''
|
''' initializes an empty stack '''
|
||||||
self._data = LinkedList()
|
self._data = LinkedList()
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
''' allows the len function to be called using an ArrayStack object, e.g.,
|
''' allows the len function to be called using an ArrayStack object, e.g.,
|
||||||
stack = ArrayStack()
|
stack = ArrayStack()
|
||||||
@@ -29,7 +29,7 @@ class Stack[T]:
|
|||||||
Returns:
|
Returns:
|
||||||
number of elements in the stack, as an integer
|
number of elements in the stack, as an integer
|
||||||
'''
|
'''
|
||||||
pass
|
return len(self._data)
|
||||||
|
|
||||||
def push(self, item: T) -> None:
|
def push(self, item: T) -> None:
|
||||||
''' pushes a given item of arbitrary type onto the stack
|
''' pushes a given item of arbitrary type onto the stack
|
||||||
|
|||||||
Reference in New Issue
Block a user