Binary Search Tree : Insertion

  • + 0 comments

    For those wanted to do C#, they don't have the stub code, so I wrote it.

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    
    public class Node
    {
        public int Value;
        public Node Left;
        public Node Right;
        
        public Node(int value)
        {
            Value = value;
        }
        
        public void Insert(int i)
        {
            // Write your insert code here
        }
        
        public List<int> GetTreeOrder(List<int> list = null)    
        {
            // Write your order code here
        }
    }
    
    class Solution {
                
        static void Main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
            var count = Convert.ToInt32(Console.ReadLine());
            var intArray = Console.ReadLine().Split(" ").Select(i => Convert.ToInt32(i)).ToArray();
            var rootNode = new Node(intArray[0]);
            for(int i = 1; i < intArray.Length; i++)
            {
                rootNode.Insert(intArray[i]);
            }
            var inOrder = rootNode.GetTreeOrder();
            Console.WriteLine(string.Join(" ", inOrder));
        }
    }