public NodeInterface() { var save = true; Tree <int> tree; if (save) { tree = GenerateTree(100); PersistantSerializer <Tree <int> > .Save("tree", tree); Console.WriteLine("Tree saved successfully"); } else { tree = PersistantSerializer <Tree <int> > .Load("tree"); Console.WriteLine("Tree loaded successfully"); } Console.WriteLine($"Total number of leaves: {tree.GetAllLeaves().Count()}"); Console.WriteLine("\nPress any key to exit ..."); Console.ReadKey(); }
public int GetPrime(int i) { var needSave = false; while (Primes.Count < i) { GetNextPrime(); if (!needSave) { needSave = true; } } if (needSave) { PersistantSerializer <List <int> > .Save("primes", _primes); } return(Primes[i - 1]); }
private int GetPrimeBefore(int lim) { var needSave = false; while (Primes.Last() < lim) { GetNextPrime(); if (!needSave) { needSave = true; } } if (needSave) { PersistantSerializer <List <int> > .Save("primes", _primes); } return(Primes.LastOrDefault(x => x <= lim)); }