Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # iterarive version
- class ListNode:
- def __init__(self, value, next = None):
- self.value = value
- self.next = next
- class Stack:
- def __init__(self):
- self.top = None
- self.count = 0
- def push(self, value):
- node = ListNode(value, self.top)
- self.top = node
- self.count += 1
- def is_empty(self):
- return self.top is None
- def pop(self):
- if not self.is_empty():
- current_top = self.top
- self.top = self.top.next
- return current_top.value
- def depth(self):
- if self.is_empty():
- return 0
- else:
- return print(self.count)
- c = Stack()
- c.push(12)
- c.push("Hello")
- c.push(34)
- c.depth()
Add Comment
Please, Sign In to add comment