Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. class Node():
  2.   def __init__(self, data, left=None, right=None):
  3.     self.data = data
  4.     self.left = left
  5.     self.right = right
  6.  
  7. total_iso_right_rotated_count = 0
  8.  
  9. def count_iso_right_rotated(node):
  10.   if node == None:
  11.     return 0
  12.   if node.right == None:
  13.     return -1
  14.   if node.left == None:
  15.     return 1
  16.   # first go right once
  17.   go_right_count = count_iso_right_rotated(node.right) + 1
  18.   # then go left all the way
  19.   go_left_count = count_iso_right_rotated(node.right.left)
  20.   # check if equal to zero
  21.   if go_left == 0:
  22.     total_iso_right_rotated_count += 1
  23.   return go_left_count
  24.  
  25. if __name__ == '__main__':
  26.   root = Node(1)
  27.   root.left = Node(2)
  28.   root.right = Node(3)
  29.   count_iso_right_rotated(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement