예제 #1
0
 public static int Compare(CategoryProduct first, CategoryProduct second)
 {
     return(String.Compare(first.ProductType, second.ProductType, true));
     //0 dönerse eşit
     //1 dönerse 1. Büyük
     //-1 dönerse 2. Büyük
 }
예제 #2
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);
            }
        }
예제 #3
0
        public static Product CompareProduct(CategoryProduct category, string key)
        {
            List <Product> products = category.Products;
            int            i;

            for (i = 0; i < products.Count; i++)
            {
                if (String.Compare(products[i].ProductDescription, key) == 0)
                {
                    return(products[i]);
                }
            }

            return(null);
        }
 public CategoryBSTNode(CategoryProduct Data)
 {
     this.Data = Data;
     NodeLeft  = null;
     NodeRight = null;
 }