Exemple #1
0
        public bool Insert(Product product, string productType)
        {
            CategoryBSTNode temp = root;

            CategoryBSTNode prevTemp = root;

            bool isLeft = false;

            while (temp != null)
            {
                prevTemp = temp;
                if (CompareProducts.Compare(temp.Data, productType) == 0)
                {
                    break;
                }
                else if (CompareProducts.Compare(temp.Data, productType) == 1)
                {
                    temp   = temp.NodeLeft;
                    isLeft = true;
                }
                else if (CompareProducts.Compare(temp.Data, productType) == -1)
                {
                    isLeft = false;
                    temp   = temp.NodeRight;
                }
            }

            //Hiç yok ise
            if (root == null)
            {
                CategoryProduct productCategory = new CategoryProduct(productType);
                CategoryBSTNode category        = new CategoryBSTNode(productCategory);
                root = category;
                productCategory.Insert(product);
                return(true);
            }

            //Ürün tipi yok ise
            if (temp == null)
            {
                CategoryProduct category = new CategoryProduct(productType);
                category.Insert(product);
                if (isLeft)
                {
                    prevTemp.NodeLeft = new CategoryBSTNode(category);
                }
                else
                {
                    prevTemp.NodeRight = new CategoryBSTNode(category);
                }
                return(true);
            }
            //Ürün tipi mevcut ise
            else
            {
                ///TODO : Aynı product' tan olması durumu
                temp.Data.Insert(product);
                return(true);
            }
        }
Exemple #2
0
 public CategoryBSTNode SearchCategotyProduct(CategoryBSTNode node, string key)
 {
     if (node == null)
     {
         return(null);
     }
     else if (CompareProducts.Compare(node.Data, key) == 0)
     {
         return(node);
     }
     else if (CompareProducts.Compare(node.Data, key) == 1)
     {
         return(SearchCategotyProduct(node.NodeLeft, key));
     }
     else
     {
         return(SearchCategotyProduct(node.NodeRight, key));
     }
 }