
"""simple docstring"""

from collections.abc import Iterable
from typing import Any
class      _UpperCAmelCase							:




      def __init__(							self   ,       lowercase_ = None							)						->					List[str]:
          UpperCAmelCase									=					value
          UpperCAmelCase									=					None  # Added in order to delete a node easier
          UpperCAmelCase									=					None
          UpperCAmelCase									=					None




      def __repr__(							self							)						->					List[str]:
          from pprint import pformat

          if self.left is None and self.right is None:
              return str(self.value							)
          return pformat({F"{self.value}": (self.left, self.right)}   ,       indent=1							)

class      _UpperCAmelCase							:




      def __init__(							self   ,       lowercase_ = None							)						->					List[Any]:
          UpperCAmelCase									=					root




      def __str__(							self							)						->					Optional[Any]:
          return str(self.root							)




      def     a_      (							self   ,       lowercase_   ,       lowercase_							)						->					int:
          if new_children is not None:  # reset its kids
              UpperCAmelCase									=					node.parent
          if node.parent is not None:  # reset its parent
              if self.is_right(lowercase_							):  # If it is the right children
                  UpperCAmelCase									=					new_children
              else:
                  UpperCAmelCase									=					new_children
          else:
              UpperCAmelCase									=					new_children




      def     a_      (							self   ,       lowercase_							)						->					Tuple:
          if node.parent and node.parent.right:
              return node == node.parent.right
          return False




      def     a_      (							self							)						->					int:
          return self.root is None




      def     a_      (							self   ,       lowercase_							)						->					List[Any]:
          UpperCAmelCase									=					Node(lowercase_							)  # create a new Node
          if self.empty():  # if Tree is empty
              UpperCAmelCase									=					new_node  # set its root
          else:  # Tree is not empty
              UpperCAmelCase									=					self.root  # from root
              if parent_node is None:
                  return
              while True:  # While we don't get to a leaf
                  if value < parent_node.value:  # We go left
                      if parent_node.left is None:
                          UpperCAmelCase									=					new_node  # We insert the new node in a leaf
                          break
                      else:
                          UpperCAmelCase									=					parent_node.left
                  else:
                      if parent_node.right is None:
                          UpperCAmelCase									=					new_node
                          break
                      else:
                          UpperCAmelCase									=					parent_node.right
              UpperCAmelCase									=					parent_node




      def     a_      (							self   ,       *lowercase_							)						->					Optional[int]:
          for value in values:
              self.__insert(lowercase_							)




      def     a_      (							self   ,       lowercase_							)						->					Dict:
          if self.empty():
              raise IndexError('Warning: Tree is empty! please use another.'							)
          else:
              UpperCAmelCase									=					self.root
              # use lazy evaluation here to avoid NoneType Attribute error
              while node is not None and node.value is not value:
                  UpperCAmelCase									=					node.left if value < node.value else node.right
              return node




      def     a_      (							self   ,       lowercase_ = None							)						->					Tuple:
          if node is None:
              if self.root is None:
                  return None
              UpperCAmelCase									=					self.root

          if not self.empty():
              while node.right is not None:
                  UpperCAmelCase									=					node.right
          return node




      def     a_      (							self   ,       lowercase_ = None							)						->					List[str]:
          if node is None:
              UpperCAmelCase									=					self.root
          if self.root is None:
              return None
          if not self.empty():
              UpperCAmelCase									=					self.root
              while node.left is not None:
                  UpperCAmelCase									=					node.left
          return node




      def     a_      (							self   ,       lowercase_							)						->					Any:
          UpperCAmelCase									=					self.search(lowercase_							)  # Look for the node with that label
          if node is not None:
              if node.left is None and node.right is None:  # If it has no children
                  self.__reassign_nodes(lowercase_   ,       lowercase_							)
              elif node.left is None:  # Has only right children
                  self.__reassign_nodes(lowercase_   ,       node.right							)
              elif node.right is None:  # Has only left children
                  self.__reassign_nodes(lowercase_   ,       node.left							)
              else:
                  UpperCAmelCase									=					self.get_max(
                      node.left							)  # Gets the max value of the left branch
                  self.remove(tmp_node.value							)  # type: ignore
                  UpperCAmelCase									=					(
                      tmp_node.value  # type: ignore
                  )  # Assigns the value to the node to delete and keep tree structure




      def     a_      (							self   ,       lowercase_							)						->					Optional[Any]:
          if node is not None:
              yield node  # Preorder Traversal
              yield from self.preorder_traverse(node.left							)
              yield from self.preorder_traverse(node.right							)




      def     a_      (							self   ,       lowercase_=None							)						->					str:
          if traversal_function is None:
              return self.preorder_traverse(self.root							)
          else:
              return traversal_function(self.root							)




      def     a_      (							self   ,       lowercase_   ,       lowercase_							)						->					str:
          if node:
              self.inorder(lowercase_   ,       node.left							)
              arr.append(node.value							)
              self.inorder(lowercase_   ,       node.right							)




      def     a_      (							self   ,       lowercase_   ,       lowercase_							)						->					Tuple:
          UpperCAmelCase									=					[]
          self.inorder(lowercase_   ,       lowercase_							)  # append all values to list using inorder traversal
          return arr[k - 1]




def     lowercase__						(					lowerCAmelCase				:					Optional[int] ) ->      List[Any]:






    """simple docstring"""




    UpperCAmelCase									=					[]
    if curr_node is not None:
        UpperCAmelCase									=					postorder(curr_node.left ) + postorder(curr_node.right ) + [curr_node]
    return node_list




def     lowercase__						(					) ->      Any:






    """simple docstring"""




    UpperCAmelCase									=					(8, 3, 6, 1, 10, 14, 13, 4, 7)
    UpperCAmelCase									=					BinarySearchTree()
    for i in testlist:
        t.insert(_snake_case )

    # Prints all the elements of the list in order traversal
    print(_snake_case )

    if t.search(6 ) is not None:
        print('The value 6 exists' )
    else:
        print('The value 6 doesn\'t exist' )

    if t.search(-1 ) is not None:
        print('The value -1 exists' )
    else:
        print('The value -1 doesn\'t exist' )

    if not t.empty():
        print('Max Value: ' ,				t.get_max().value )  # type: ignore
        print('Min Value: ' ,				t.get_min().value )  # type: ignore

    for i in testlist:
        t.remove(_snake_case )
        print(_snake_case )


if __name__ == "__main__":
   import doctest

   doctest.testmod(verbose=True)





"""simple docstring"""

import sys
import turtle




def     lowercase__						(					lowerCAmelCase				:					tuple[float, float] ,				lowerCAmelCase				:					tuple[float, float] ) ->      tuple[float, float]:






    """simple docstring"""




    return (pa[0] + pa[0]) / 2, (pa[1] + pa[1]) / 2




def     lowercase__						(					lowerCAmelCase				:					tuple[float, float] ,				lowerCAmelCase				:					tuple[float, float] ,				lowerCAmelCase				:					tuple[float, float] ,				lowerCAmelCase				:					int ,				) ->      None:






    """simple docstring"""




    my_pen.up()
    my_pen.goto(vertexa[0] ,				vertexa[1] )
    my_pen.down()
    my_pen.goto(vertexa[0] ,				vertexa[1] )
    my_pen.goto(vertexa[0] ,				vertexa[1] )
    my_pen.goto(vertexa[0] ,				vertexa[1] )

    if depth == 0:
        return

    triangle(lowerCAmelCase ,				get_mid(lowerCAmelCase ,				lowerCAmelCase ) ,				get_mid(lowerCAmelCase ,				lowerCAmelCase ) ,				depth - 1 )
    triangle(lowerCAmelCase ,				get_mid(lowerCAmelCase ,				lowerCAmelCase ) ,				get_mid(lowerCAmelCase ,				lowerCAmelCase ) ,				depth - 1 )
    triangle(lowerCAmelCase ,				get_mid(lowerCAmelCase ,				lowerCAmelCase ) ,				get_mid(lowerCAmelCase ,				lowerCAmelCase ) ,				depth - 1 )


if __name__ == "__main__":
   if len(sys.argv) != 2:
      raise ValueError(
          '''Correct format for using this script: '''
          '''python fractals.py <int:depth_for_fractal>'''
      )
   SCREAMING_SNAKE_CASE_    					=						turtle.Turtle()
   my_pen.ht()
   my_pen.speed(5)
   my_pen.pencolor('''red''')

   SCREAMING_SNAKE_CASE_    					=						[(-175, -125), (0, 175), (175, -125)]  # vertices of triangle
   triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))



