/* Apply all the transfers made */ public void ApplyTransfers(Transfers transfers) { foreach (Transfer t in transfers.transactions) { int amount = t.amount; List <User> branch = GetBranchAbove(t.from); User last = this.root; foreach (User user in branch) { int am = (int)Math.Floor((double)amount / 2); user.Prov += am; amount -= am; last = user; } last.Prov += amount; } }
static void Main(string[] args) { string dirPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; XmlDeserializer xmlDeserializer = new XmlDeserializer(); Pyramid pyramid = xmlDeserializer.Deserialize <Pyramid>(dirPath + @"\pyramid.xml"); pyramid.CreateList(pyramid.root); Transfers transfers = xmlDeserializer.Deserialize <Transfers>(dirPath + @"\transfers.xml"); pyramid.ApplyTransfers(transfers); foreach (User u in pyramid.UserList) { Console.WriteLine(u.id + " " + u.Level + " " + u.LeavesUnder + " " + u.Prov); } Console.ReadKey(); }