public void preOrder(ProductGroupTreeNode root)
 {
     if (root != null)
     {
         ProductNode.Add(root);
         preOrder(root.LeftChild);
         preOrder(root.RightChid);
     }
 }
 public void düzeyListele(ProductGroupTreeNode etkin, int d)
 {
     if (etkin != null)
     {
         d = d + 1;
         düzeyListele(etkin.LeftChild, d);
         //Console.WriteLine(" " + etkin.ProductBase.ProductGroupName + " " + d + ". düzeyde");
         düzeyListele(etkin.RightChid, d);
     }
 }
 public void GetAllProductByProductGroupName(ProductGroupTreeNode root, string productGroupName)
 {
     if (root != null)
     {
         if (root.ProductBase.ProductGroupName == productGroupName)
         {
             GetAllProduct.AddRange(root.ProductBase.Products);
         }
         else
         {
             GetAllProductByProductGroupName(root.LeftChild, productGroupName);
             GetAllProductByProductGroupName(root.RightChid, productGroupName);
         }
     }
 }
 public void GetAllProductPriceBetween(ProductGroupTreeNode root, decimal productPriceBegin, decimal productPriceLast)
 {
     if (root != null)
     {
         foreach (var item in root.ProductBase.Products)
         {
             if (item.ProductPrice >= productPriceBegin && item.ProductPrice <= productPriceLast)
             {
                 ProductsBetween.Add(item);
             }
         }
         GetAllProductPriceBetween(root.LeftChild, productPriceBegin, productPriceLast);
         GetAllProductPriceBetween(root.RightChid, productPriceBegin, productPriceLast);
     }
 }
 public void inOrderForProductsAllProduct(ProductGroupTreeNode root)
 {
     if (root != null)
     {
         foreach (var item in root.ProductBase.Products.ToList())
         {
             if (item.ProductNumber > 0)
             {
                 AllProductByCategoryName.Add(item);
             }
         }
         ProductTotalSize = ProductTotalSize + root.ProductBase.Products.Count;
         inOrderForProductsAllProduct(root.LeftChild);
         inOrderForProductsAllProduct(root.RightChid);
     }
 }
        public void DeleteProducts(ProductGroupTreeNode root, List <int> productIds)
        {
            if (root != null)
            {
                foreach (var item in productIds)
                {
                    var product = root.ProductBase.Products.Where(x => x.ProductId == item).FirstOrDefault();
                    if (product != null)
                    {
                        product.ProductNumber = product.ProductNumber - 1;
                    }
                }

                DeleteProducts(root.LeftChild, productIds);
                DeleteProducts(root.RightChid, productIds);
            }
        }
        public void findTreeInfo(ProductGroupTreeNode rootNode, int treeSize)
        {
            totalDepth = 0;
            maxDepth   = 0;

            elementCountForEachDepth    = new int[treeSize];
            sumElementCountForEachDepth = new string[treeSize];

            traverseTreeForInfo(rootNode, -1);

            //Console.WriteLine("\nDepth of the tree: " + maxDepth);
            //Console.WriteLine("Element counts for each depth");
            //for (int i = 0; i <= maxDepth; i++)
            //{
            //    Console.WriteLine("\tFor depth {0}: Number of elements: {1}  Sum of elements {2}", i, elementCountForEachDepth[i], sumElementCountForEachDepth[i]);
            //}
            //Console.WriteLine("Average depth: " + ((double)totalDepth / treeSize));
        }
        private void traverseTreeForInfo(ProductGroupTreeNode node, int depth)
        {
            if (node != null)
            {
                depth++;

                elementCountForEachDepth[depth]++;
                sumElementCountForEachDepth[depth] += node.ProductBase.ProductGroupName;

                if (depth > maxDepth)
                {
                    maxDepth = depth; //update max depth
                }
                totalDepth += depth;

                traverseTreeForInfo(node.LeftChild, depth); //traverse left sub-tree
                traverseTreeForInfo(node.RightChid, depth); //traverse right sub-tree
            }
        }
 public ProductGroupTreeNode GetProductTreeNodeByProductGroupName(ProductGroupTreeNode root, string productGroupName)
 {
     if (root != null)
     {
         if (root.ProductBase.ProductGroupName == productGroupName)
         {
             return(root);
         }
         if (root.ProductBase.ProductGroupName.CompareTo(productGroupName) == 0)
         {
             return(GetProductTreeNodeByProductGroupName(root.LeftChild, productGroupName));
         }
         else
         {
             return(GetProductTreeNodeByProductGroupName(root.RightChid, productGroupName));
         }
     }
     else
     {
         return(new ProductGroupTreeNode());
     }
 }
        public void insert(ProductGroup newProductBase)
        {
            ProductGroupTreeNode newNode = new ProductGroupTreeNode();

            newNode.ProductBase = newProductBase;
            TreeSize++;
            if (root == null)
            {
                root = newNode;
            }
            else
            {
                ProductGroupTreeNode current = root;
                ProductGroupTreeNode parent;
                while (true)
                {
                    parent = current;
                    if (newNode.ProductBase.ProductGroupName.CompareTo(current.ProductBase.ProductGroupName) == 0)
                    {
                        current = current.LeftChild;
                        if (current == null)
                        {
                            parent.LeftChild = newNode;
                            return;
                        }
                    }
                    else
                    {
                        current = current.RightChid;
                        if (current == null)
                        {
                            parent.RightChid = newNode;
                            return;
                        }
                    }
                }
            }
        }