Remove vowels from a string stored in a Binary Tree | C # program for the above approach ; Structure Representing the Node in the Binary tree ; Function to perform a level order insertion of a new Node in the Binary tree ; If the root is empty , make it point to the new 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 new Node as the left child ; In case the right child does not exist , insert the new 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 new Binary tree ; Declaring the root of the new tree ; If the given character is not a vowel , add it to the new Binary tree ; Driver code
using System ; using System . Collections . Generic ; class GFG { class Node { public char data ; public Node left , right ; public Node ( char _val ) { data = _val ; left = right = null ; } } ; static Node addinBT ( Node root , char data ) { if ( root == null ) { root = new Node ( data ) ; } else { List < Node > Q = new List < Node > ( ) ; Q . Add ( root ) ; while ( Q . Count != 0 ) { Node temp = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; if ( temp . left == null ) { temp . left = new Node ( data ) ; break ; } else Q . Add ( temp . left ) ; if ( temp . right == null ) { temp . right = new Node ( data ) ; break ; } else Q . Add ( temp . right ) ; } } return root ; } static void print ( Node root ) { List < Node > Q = new List < Node > ( ) ; Q . Add ( root ) ; while ( Q . Count > 0 ) { Node temp = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; Console . Write ( temp . data ) ; if ( temp . left != null ) Q . Add ( temp . left ) ; if ( temp . right != null ) Q . Add ( temp . right ) ; } } static bool checkvowel ( char ch ) { ch = char . ToLower ( ch ) ; if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) { return true ; } else { return false ; } } static Node removevowels ( Node root ) { List < Node > Q = new List < Node > ( ) ; Q . Add ( root ) ; Node root1 = null ; while ( Q . Count != 0 ) { Node temp = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; if ( ! checkvowel ( temp . data ) ) { root1 = addinBT ( root1 , temp . data ) ; } if ( temp . left != null ) { Q . Add ( temp . left ) ; } if ( temp . right != null ) { Q . Add ( temp . right ) ; } } return root1 ; } public static void Main ( String [ ] args ) { String s = " geeks " ; Node root = null ; for ( int i = 0 ; i < s . Length ; i ++ ) { root = addinBT ( root , s [ i ] ) ; } root = removevowels ( root ) ; print ( root ) ; } }