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 }
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); } }
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; }