Remove vowels from a string stored in a Binary Tree | Structure Representing the Node in the Binary tree ; Function to perform a level order insertion of a Node in the Binary tree ; If the root is empty , make it point to the Node ; In case there are elements in the Binary tree , perform a level order traversal using a Queue ; If the left child does not exist , insert the Node as the left child ; In case the right child does not exist , insert the Node as the right child ; Function to print the level order traversal of the Binary tree ; Function to check if the character is a vowel or not . ; Function to remove the vowels in the Binary tree ; Declaring the root of the tree ; If the given character is not a vowel , add it to the Binary tree ; Driver code
class Node : NEW_LINE INDENT def __init__ ( self , _val ) : NEW_LINE INDENT self . data = _val NEW_LINE self . left = self . right = None NEW_LINE DEDENT DEDENT def addinBT ( root , data ) : NEW_LINE INDENT if ( root == None ) : NEW_LINE INDENT root = Node ( data ) NEW_LINE DEDENT else : NEW_LINE INDENT Q = [ ] NEW_LINE Q . append ( root ) NEW_LINE while ( len ( Q ) > 0 ) : NEW_LINE INDENT temp = Q [ - 1 ] NEW_LINE Q . pop ( ) NEW_LINE if ( temp . left == None ) : NEW_LINE INDENT temp . left = Node ( data ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT Q . append ( temp . left ) NEW_LINE DEDENT if ( temp . right == None ) : NEW_LINE INDENT temp . right = Node ( data ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT Q . append ( temp . right ) NEW_LINE DEDENT DEDENT DEDENT return root NEW_LINE DEDENT def print_ ( root ) : NEW_LINE INDENT Q = [ ] NEW_LINE Q . append ( root ) NEW_LINE while ( len ( Q ) > 0 ) : NEW_LINE INDENT temp = Q [ - 1 ] NEW_LINE Q . pop ( ) NEW_LINE print ( temp . data , end = " ▁ " ) NEW_LINE if ( temp . left != None ) : NEW_LINE INDENT Q . append ( temp . left ) NEW_LINE DEDENT if ( temp . right != None ) : NEW_LINE INDENT Q . append ( temp . right ) NEW_LINE DEDENT DEDENT DEDENT def checkvowel ( ch ) : NEW_LINE INDENT ch = ch . lower ( ) NEW_LINE if ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def removevowels ( root ) : NEW_LINE INDENT Q = [ ] NEW_LINE Q . append ( root ) NEW_LINE root1 = None NEW_LINE while ( len ( Q ) > 0 ) : NEW_LINE INDENT temp = Q [ - 1 ] NEW_LINE Q . pop ( ) NEW_LINE if ( not checkvowel ( temp . data ) ) : NEW_LINE INDENT root1 = addinBT ( root1 , temp . data ) NEW_LINE DEDENT if ( temp . left != None ) : NEW_LINE INDENT Q . append ( temp . left ) NEW_LINE DEDENT if ( temp . right != None ) : NEW_LINE INDENT Q . append ( temp . right ) NEW_LINE DEDENT DEDENT return root1 NEW_LINE DEDENT s = " geeks " NEW_LINE root = None NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT root = addinBT ( root , s [ i ] ) NEW_LINE DEDENT root = removevowels ( root ) NEW_LINE print_ ( root ) NEW_LINE