public bool Find(string s) { bool found = false; if (data.Equals(s)) { found = true; } else { if (AlphNumBST.CompareString(s, data) == CompareCharResult.FirstLess || AlphNumBST.CompareString(s, data) == CompareCharResult.Same) { if (leftChild != null) { found = leftChild.Find(s); } } else { if (rightChild != null) { found = rightChild.Find(s); } } } return(found); }
private void Add(string s) { if (_root == null) { _root = new TreeNode(s); } else { if (!Find(s)) { TreeNode node = _root; while (true) { if (AlphNumBST.CompareString(s, node.data) == CompareCharResult.FirstLess || AlphNumBST.CompareString(s, node.data) == CompareCharResult.Same) { if (node.leftChild == null) { node.leftChild = new TreeNode(s); break; } else { node = node.leftChild; } } else { if (node.rightChild == null) { node.rightChild = new TreeNode(s); break; } else { node = node.rightChild; } } } } } }
private void GetItemShops() { XmlNodeList shops = _xml ["data"]["itemShops"].ChildNodes; foreach (XmlNode shopN in shops) { ItemShop shop = new ItemShop(); shop.id = Convert.ToInt32(shopN.Attributes ["id"].Value); shop.name = shopN.Attributes ["name"].Value; shop.greeting = shopN.Attributes ["greeting"].Value; shop.sellTabText = shopN.Attributes ["sellTabText"].Value; shop.buyTabText = shopN.Attributes ["buyTabText"].Value; shop.boughtText = shopN.Attributes ["boughtText"].Value; shop.cannotAffordText = shopN.Attributes ["cannotAffordText"].Value; shop.alreadyHaveItemText = shopN.Attributes ["alreadyHaveItemText"].Value; shop.sellItemIDs = new List <int> { }; shop.sellPrices = new List <int> { }; shop.sortMode = (ItemShop.SortMode)Enum.Parse(typeof(ItemShop.SortMode), shopN.Attributes ["sortMode"].Value); string [] itemsAndPrices = shopN.Attributes ["sellItems"].Value.Split(new char [] { ',' }); if (itemsAndPrices [0].Length > 0) { foreach (string s in itemsAndPrices) { shop.sellItemIDs.Add(Convert.ToInt32(s.Substring(0, s.IndexOf("-")))); shop.sellPrices.Add(Convert.ToInt32(s.Substring(s.IndexOf("-") + 1))); } if (shop.sortMode == ItemShop.SortMode.ByName) { List <string> sortedItemNames = new List <string> { }; for (int i = 0; i < shop.sellItemIDs.Count(); i++) { sortedItemNames.Add(Data._itemInfo.items.Find(theItem => theItem.id == shop.sellItemIDs [i]).name); } List <string> unsortedItemNames = new List <string> (sortedItemNames); sortedItemNames = new AlphNumBST(sortedItemNames).GetStrings(); SortArraysByName(unsortedItemNames, sortedItemNames, new List <List <int> > { shop.sellItemIDs, shop.sellPrices }); } else if (shop.sortMode == ItemShop.SortMode.ByPrice) { List <int> unsortedItemPrices = shop.sellPrices; List <int> sortedItemPrices = new NumBST(unsortedItemPrices).GetNums(); SortArraysByNumber(unsortedItemPrices, sortedItemPrices, shop.sellItemIDs, shop.sellPrices); } } shop.soldText = shopN.Attributes ["soldText"].Value; shop.notEnoughText = shopN.Attributes ["notEnoughText"].Value; shop.buyItemIDs = new List <int> { }; shop.buyPrices = new List <int> { }; itemsAndPrices = shopN.Attributes ["buyItems"].Value.Split(new char [] { ',' }); if (itemsAndPrices [0].Length > 0) { foreach (string s in itemsAndPrices) { shop.buyItemIDs.Add(Convert.ToInt32(s.Substring(0, s.IndexOf("-")))); shop.buyPrices.Add(Convert.ToInt32(s.Substring(s.IndexOf("-") + 1))); } if (shop.sortMode == ItemShop.SortMode.ByName) { List <string> sortedItemNames = new List <string> { }; for (int i = 0; i < shop.buyItemIDs.Count(); i++) { sortedItemNames.Add(Data._itemInfo.items.Find(theItem => theItem.id == shop.buyItemIDs [i]).name); } List <string> unsortedItemNames = new List <string> (sortedItemNames); sortedItemNames = new AlphNumBST(sortedItemNames).GetStrings(); SortArraysByName(unsortedItemNames, sortedItemNames, new List <List <int> > { shop.buyItemIDs, shop.buyPrices }); } else if (shop.sortMode == ItemShop.SortMode.ByPrice) { List <int> unsortedItemPrices = shop.buyPrices; List <int> sortedItemPrices = new NumBST(unsortedItemPrices).GetNums(); SortArraysByNumber(unsortedItemPrices, sortedItemPrices, shop.buyItemIDs, shop.buyPrices); } } _itemShops.Add(shop); } }