Guest User

Untitled

a guest
Oct 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. # iterarive version
  2.  
  3. class ListNode:
  4.  
  5. def __init__(self, value, next = None):
  6. self.value = value
  7. self.next = next
  8.  
  9. class Stack:
  10.  
  11. def __init__(self):
  12. self.top = None
  13. self.count = 0
  14.  
  15. def push(self, value):
  16. node = ListNode(value, self.top)
  17. self.top = node
  18. self.count += 1
  19.  
  20. def is_empty(self):
  21. return self.top is None
  22.  
  23. def pop(self):
  24. if not self.is_empty():
  25. current_top = self.top
  26. self.top = self.top.next
  27. return current_top.value
  28.  
  29. def depth(self):
  30. if self.is_empty():
  31. return 0
  32. else:
  33. return print(self.count)
  34.  
  35. c = Stack()
  36. c.push(12)
  37. c.push("Hello")
  38. c.push(34)
  39. c.depth()
Add Comment
Please, Sign In to add comment