Пример #1
0
        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();
        }
Пример #2
0
        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]);
        }
Пример #3
0
        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));
        }