


from __future__ import annotations

import queue







class 	snake_case_       :
					def __init__(				self       :Any      ,__snake_case       :Optional[int]				) ->   List[str]:
												a__					=					data
												a__					=					None
												a__					=					None






def 							__lowercase       (			):
							print('\n********Press N to stop entering at any point of time********\n'       )
							a__					=					input('Enter the value of the root node: '       ).strip().lower()
							a__					=					queue.Queue()
							a__					=					TreeNode(int(__lowerCAmelCase       )       )
							q.put(__lowerCAmelCase       )
							while not q.empty():
														a__					=					q.get()
														a__					=					F'Enter the left node of {node_found.data}: '
														a__					=					input(__lowerCAmelCase       ).strip().lower() or 'n'
														if check == "n":
																					return tree_node
														a__					=					TreeNode(int(__lowerCAmelCase       )       )
														a__					=					left_node
														q.put(__lowerCAmelCase       )
														a__					=					F'Enter the right node of {node_found.data}: '
														a__					=					input(__lowerCAmelCase       ).strip().lower() or 'n'
														if check == "n":
																					return tree_node
														a__					=					TreeNode(int(__lowerCAmelCase       )       )
														a__					=					right_node
														q.put(__lowerCAmelCase       )
							raise






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							print(node.data ,   end=','       )
							pre_order(node.left       )
							pre_order(node.right       )






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							in_order(node.left       )
							print(node.data ,   end=','       )
							in_order(node.right       )






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							post_order(node.left       )
							post_order(node.right       )
							print(node.data ,   end=','       )






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							a__					=					queue.Queue()
							q.put(__lowerCAmelCase       )
							while not q.empty():
														a__					=					q.get()
														print(node_dequeued.data ,   end=','       )
														if node_dequeued.left:
																					q.put(node_dequeued.left       )
														if node_dequeued.right:
																					q.put(node_dequeued.right       )






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							a__					=					queue.Queue()
							q.put(__lowerCAmelCase       )
							while not q.empty():
														a__					=					[]
														while not q.empty():
																					a__					=					q.get()
																					print(node_dequeued.data ,   end=','       )
																					if node_dequeued.left:
																												list_.append(node_dequeued.left       )
																					if node_dequeued.right:
																												list_.append(node_dequeued.right       )
														print()
														for node in list_:
																					q.put(__lowerCAmelCase       )






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							a__					=					[]
							a__					=					node
							while n or stack:
														while n:  # start from root node, find its left child
																					print(n.data ,   end=','       )
																					stack.append(__lowerCAmelCase       )
																					a__					=					n.left
														# end of while means current node doesn't have left child
														a__					=					stack.pop()
														# start to traverse its right child
														a__					=					n.right






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							a__					=					[]
							a__					=					node
							while n or stack:
														while n:
																					stack.append(__lowerCAmelCase       )
																					a__					=					n.left
														a__					=					stack.pop()
														print(n.data ,   end=','       )
														a__					=					n.right






def 							__lowercase       (			__lowerCAmelCase							:    TreeNode       ):
							if not isinstance(__lowerCAmelCase ,   __lowerCAmelCase       ) or not node:
														return
							a__				, a__					=					[], []
							a__					=					node
							stacka.append(__lowerCAmelCase       )
							while stacka:  # to find the reversed order of post order, store it in stack2
														a__					=					stacka.pop()
														if n.left:
																					stacka.append(n.left       )
														if n.right:
																					stacka.append(n.right       )
														stacka.append(__lowerCAmelCase       )
							while stacka:  # pop up from stack2 will be the post order
														print(stacka.pop().data ,   end=','       )






def 							__lowercase       (			__lowerCAmelCase							:    str = "" ,   __lowerCAmelCase							:    str=5_0 ,   __lowerCAmelCase							:    Dict="*"       ):
							if not s:
														return "\n" + width * char
							a__				, a__					=					divmod(width - len(__lowerCAmelCase       ) - 2 ,   2       )
							return F'{left * char} {s} {(left + extra) * char}'


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						print(prompt('''Binary Tree Traversals'''))

						snake_case							:	TreeNode					      =				build_tree()
						print(prompt('''Pre Order Traversal'''))
						pre_order(node)
						print(prompt() + '''\n''')

						print(prompt('''In Order Traversal'''))
						in_order(node)
						print(prompt() + '''\n''')

						print(prompt('''Post Order Traversal'''))
						post_order(node)
						print(prompt() + '''\n''')

						print(prompt('''Level Order Traversal'''))
						level_order(node)
						print(prompt() + '''\n''')

						print(prompt('''Actual Level Order Traversal'''))
						level_order_actual(node)
						print('''*''' * 50 + '''\n''')

						print(prompt('''Pre Order Traversal - Iteration Version'''))
						pre_order_iter(node)
						print(prompt() + '''\n''')

						print(prompt('''In Order Traversal - Iteration Version'''))
						in_order_iter(node)
						print(prompt() + '''\n''')

						print(prompt('''Post Order Traversal - Iteration Version'''))
						post_order_iter(node)
						print(prompt())








snake_case							:	str					      =				{
    0: '''0''',
    1: '''1''',
    2: '''2''',
    3: '''3''',
    4: '''4''',
    5: '''5''',
    6: '''6''',
    7: '''7''',
    8: '''8''',
    9: '''9''',
    10: '''a''',
    11: '''b''',
    12: '''c''',
    13: '''d''',
    14: '''e''',
    15: '''f''',
}






def 							__lowercase       (			__lowerCAmelCase							:    float       ):
							assert type(__lowerCAmelCase       ) in (int, float) and decimal == int(__lowerCAmelCase       )
							a__					=					int(__lowerCAmelCase       )
							a__					=					''
							a__					=					False
							if decimal < 0:
														a__					=					True
														decimal *= -1
							while decimal > 0:
														a__				, a__					=					divmod(__lowerCAmelCase ,   1_6       )
														a__					=					values[remainder] + hexadecimal
							a__					=					'0x' + hexadecimal
							if negative:
														a__					=					'-' + hexadecimal
							return hexadecimal


if __name__ == "__main__":
						import doctest

						doctest.testmod()




