



"""simple docstring"""





from __future__ import annotations

from collections import deque
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Any




@dataclass
class 			lowercase__			:
							'''simple docstring'''







							_UpperCAmelCase      				=					42
							_UpperCAmelCase      				=					None
							_UpperCAmelCase      				=					None







def 	UpperCAmelCase     (		):

		'''simple docstring'''


		_UpperCAmelCase							 =		Node(1       )
		_UpperCAmelCase							 =		Node(2       )
		_UpperCAmelCase							 =		Node(3       )
		_UpperCAmelCase							 =		Node(4       )
		_UpperCAmelCase							 =		Node(5       )
		return tree




def 	UpperCAmelCase     (		A	:						Node | None       ):

		'''simple docstring'''


		return [root.data, *preorder(root.left       ), *preorder(root.right       )] if root else []




def 	UpperCAmelCase     (		A	:						Node | None       ):

		'''simple docstring'''


		return postorder(root.left       ) + postorder(root.right       ) + [root.data] if root else []




def 	UpperCAmelCase     (		A	:						Node | None       ):

		'''simple docstring'''


		return [*inorder(root.left       ), root.data, *inorder(root.right       )] if root else []




def 	UpperCAmelCase     (		A	:						Node | None       ):

		'''simple docstring'''


		return (max(height(root.left       )     ,				height(root.right       )       ) + 1) if root else 0




def 	UpperCAmelCase     (		A	:						Node | None       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		[]

		if root is None:
				return output

		_UpperCAmelCase							 =		deque([root]       )

		while process_queue:
				_UpperCAmelCase							 =		process_queue.popleft()
				output.append(node.data       )

				if node.left:
						process_queue.append(node.left       )
				if node.right:
						process_queue.append(node.right       )
		return output




def 	UpperCAmelCase     (		A	:						Node | None     ,				A	:						int       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		[]

		def populate_output(A	:						Node | None     ,				A	:						int       ) -> None:
				if not root:
						return
				if level == 1:
						output.append(root.data       )
				elif level > 1:
						populate_output(root.left     ,				level - 1       )
						populate_output(root.right     ,				level - 1       )

		populate_output(A     ,				A       )
		return output




def 	UpperCAmelCase     (		A	:						Node | None     ,				A	:						int       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		[]

		def populate_output(A	:						Node | None     ,				A	:						int       ) -> None:
				if root is None:
						return
				if level == 1:
						output.append(root.data       )
				elif level > 1:
						populate_output(root.right     ,				level - 1       )
						populate_output(root.left     ,				level - 1       )

		populate_output(A     ,				A       )
		return output




def 	UpperCAmelCase     (		A	:						Node | None       ):

		'''simple docstring'''


		if root is None:
				return []

		_UpperCAmelCase							 =		[]

		_UpperCAmelCase							 =		0
		_UpperCAmelCase							 =		height(A       )

		for h in range(1     ,				height_tree + 1       ):
				if not flag:
						output.append(get_nodes_from_left_to_right(A     ,				A       )       )
						_UpperCAmelCase							 =		1
				else:
						output.append(get_nodes_from_right_to_left(A     ,				A       )       )
						_UpperCAmelCase							 =		0

		return output




def 	UpperCAmelCase     (		):  # Main function for testing.

		'''simple docstring'''


		_UpperCAmelCase							 =		make_tree()
		print(f'In-order Traversal: {inorder(A       )}'       )
		print(f'Pre-order Traversal: {preorder(A       )}'       )
		print(f'Post-order Traversal: {postorder(A       )}'     ,				'\n'       )

		print(f'Height of Tree: {height(A       )}'     ,				'\n'       )

		print('Complete Level Order Traversal: '       )
		print(level_order(A       )     ,				'\n'       )

		print('Level-wise order Traversal: '       )

		for level in range(1     ,				height(A       ) + 1       ):
				print(f'Level {level}:'     ,				get_nodes_from_left_to_right(A     ,				level=A       )       )

		print('\nZigZag order Traversal: '       )
		print(zigzag(A       )       )


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()







"""simple docstring"""





from __future__ import annotations




def 	UpperCAmelCase     (		A	:						int     ,				A	:						int       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		[]
		create_all_state(1     ,				A     ,				A     ,				[]     ,				A       )
		return result




def 	UpperCAmelCase     (		A	:						int     ,				A	:						int     ,				A	:						int     ,				A	:						list[int]     ,				A	:						list[list[int]]     ,				):

		'''simple docstring'''


		if level == 0:
				total_list.append(current_list[:]       )
				return

		for i in range(A     ,				total_number - level + 2       ):
				current_list.append(A       )
				create_all_state(i + 1     ,				A     ,				level - 1     ,				A     ,				A       )
				current_list.pop()




def 	UpperCAmelCase     (		A	:						list[list[int]]       ):

		'''simple docstring'''


		for i in total_list:
				print(*A       )


if __name__ == "__main__":
					lowercase  							=					4
					lowercase  							=					2
					lowercase  							=					generate_all_combinations(n, k)
					print_all_state(total_list)


