Exemple #1
0
        static void levelOrder(Node23 root)
        {
            //Write your code here
            getItems(root);

            Console.WriteLine(String.Join(" ", lstResult.ToArray()));
        }
Exemple #2
0
        public static void Main(String[] args)
        {
            Node23 root = null;
            int    T    = Int32.Parse(Console.ReadLine());

            while (T-- > 0)
            {
                int data = Int32.Parse(Console.ReadLine());
                root = insert(root, data);
            }
            levelOrder(root);
        }
Exemple #3
0
        static void getItems(Node23 node)
        {
            lstResult.Add(node.data);

            if (node.left != null)
            {
                qResult.Enqueue(node.left);
            }

            if (node.right != null)
            {
                qResult.Enqueue(node.right);
            }



            while (qResult.Count() > 0)
            {
                getItems(qResult.Dequeue());
            }
        }
Exemple #4
0
 private static Node23 insert(Node23 root, int data)
 {
     if (root == null)
     {
         return(new Node23(data));
     }
     else
     {
         Node23 cur;
         if (data <= root.data)
         {
             cur       = insert(root.left, data);
             root.left = cur;
         }
         else
         {
             cur        = insert(root.right, data);
             root.right = cur;
         }
         return(root);
     }
 }
Exemple #5
0
 public Node23(int data)
 {
     this.data = data;
     left      = right = null;
 }