//Алгоритм сортировки по индексам public void BubbleSort() { Offerlist Otemp = new Offerlist(); for (int i = 0; i < Offers.Length - 1; i++) { bool f = false; for (int j = 0; j < Offers.Length - i - 1; j++) { if (Offers[j + 1].Id < Offers[j].Id) { f = true; Otemp = Offers[j + 1]; Offers[j + 1] = Offers[j]; Offers[j] = Otemp; } } if (!f) { break; } } }
public void ReadData() { RP.Ulist = new List <Shoplist>(); XmlDocument xDoc = new XmlDocument(); try { xDoc.Load("Menu.xml"); } catch { MF.isError = true; MessageBox.Show("Даннi меню пошкодженi", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } finally { XmlElement xRoot = xDoc.DocumentElement; OfferCount = 0; foreach (XmlNode node in xRoot.ChildNodes) //подсчет элементов { OfferCount++; } RP.Offers = new Offerlist[OfferCount]; for (var k = 0; k < OfferCount; k++) { RP.Offers[k] = new Offerlist(); } int i = 0; List <Offerlist> Plist = new List <Offerlist>(); int f = 0; foreach (XmlNode node in xRoot.ChildNodes) { foreach (XmlNode xNode in node.ChildNodes) { if (xNode.Name == "PizzaryName") { RP.Offers[i].ShopName = xNode.InnerText; } else if (xNode.Name == "PizzaName") { RP.Offers[i].PizzaName = xNode.InnerText; } else if (xNode.Name == "PizzaRadius") { RP.Offers[i].Size = xNode.InnerText; } else if (xNode.Name == "PizzaElements") { int j = 0; foreach (XmlNode xNodeX in xNode.ChildNodes) { j++; } RP.Offers[i].Elements = new string[j]; j = 0; foreach (XmlNode xNodeX in xNode.ChildNodes) { RP.Offers[i].Elements[j] = xNodeX.InnerText; j++; } } else if (xNode.Name == "Cost") { RP.Offers[i].Cost = Convert.ToInt32(xNode.InnerText); } } //Индексирование nameindex(i); //Перечень пиццы Offerlist Ptemp = new Offerlist(); if (RP.Offers[i].Id > f) { Ptemp.Id = f = RP.Offers[i].Id; Ptemp.PizzaName = RP.Offers[i].PizzaName; Ptemp.Elements = new string[RP.Offers[i].Elements.Length]; Ptemp.Elements = RP.Offers[i].Elements; Plist.Add(Ptemp); } i++; } RP.Pizzas = Plist.ToArray(); } }