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 void PostOrderVisit(CategoryBSTNode node) { if (node == null) { return; } PostOrderVisit(node.NodeLeft); PostOrderVisit(node.NodeRight); Visit(node); }
public CategoryProduct MaxValueProduct() { CategoryBSTNode tempRight = root; while (tempRight.NodeRight != null) { tempRight = tempRight.NodeRight; } return(tempRight.Data); }
public CategoryProduct MinValueProduct() { CategoryBSTNode tempLeft = root; while (tempLeft.NodeLeft != null) { tempLeft = tempLeft.NodeLeft; } return(tempLeft.Data); }
public int ProductsCount(CategoryBSTNode node) { int count = 0; if (node != null) { count = 1; count += ProductsCount(node.NodeLeft); count += ProductsCount(node.NodeRight); } return(count); }
public Product SearchProduct(CategoryBSTNode node, string key) { throw new Exception("Kullanılmadı..."); //if (node == null) // return null; //else if (CompareProducts.CompareProduct(node.Data, key) != null ) // return node; //else if (CompareProducts.Compare(node.Data, key) == 1) // return SearchProduct(node.NodeLeft, key); //else // return SearchProduct(node.NodeRight, key); }
//TODO #region SearchCategoryProduct public CategoryProduct SearchCategoryProduct(string key) { CategoryBSTNode node = SearchCategotyProduct(root, key); if (node == null) { return(null); } else { return(node.Data); } }
private void Visit(CategoryBSTNode node) { duzeyCount++; int kalan = duzeyCount % 2; int bolum = duzeyCount / 2; if (kalan == 0 && bolum % 2 == 0) { duzey += 1; } listMessage.Add(new ListProduct { Duzey = duzey, products = node.Data.Products }); //TODO }
public int LeafCount(CategoryBSTNode node) { int count = 0; if (node != null) { if (node.NodeLeft == null && node.NodeRight == null) { count = 1; } else { count = LeafCount(node.NodeLeft) + LeafCount(node.NodeRight); } } return(count); }
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)); } }
public Product Delete(string productDescription, CategoryBSTNode node) { if (node == null) { return(null); } int i = 0; for (; i < node.Data.Products.Count; i++) { if (node.Data.Products[i].ProductDescription.Equals(productDescription)) { Product temp = node.Data.Products[i]; node.Data.Products.RemoveAt(i); return(temp); } } Product temp1 = Delete(productDescription, node.NodeLeft) ?? Delete(productDescription, node.NodeRight); return(temp1); }
public CategoryBSTNode(CategoryProduct Data) { this.Data = Data; NodeLeft = null; NodeRight = null; }
public CategoryBSTNode() { Data = null; NodeLeft = null; NodeRight = null; }
public CategoryBST(CategoryBSTNode root) { this.root = root; }