Ejemplo n.º 1
0
        public static ForwardList <T> operator >(ForwardList <T> left, ForwardList <T> right)
        {
            ForwardList <T> result = (ForwardList <T>)right.Clone();

            result.GetLast().Next = ((ForwardList <T>)left.Clone()).First;
            return(result);
        }
Ejemplo n.º 2
0
        public static long Count(this ForwardList <int> obj)
        {
            int            result = 0;
            Iterator <int> cur    = obj.First;

            while (cur != null)
            {
                result++;
                cur = cur.Next;
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static long Sum(this ForwardList <int> obj)
        {
            long           result = 0;
            Iterator <int> cur    = obj.First;

            while (cur != null)
            {
                result += cur.Value;
                cur     = cur.Next;
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static long MaxMinDiff(this ForwardList <int> obj)
        {
            long           max = long.MinValue, min = long.MaxValue;
            Iterator <int> cur = obj.First;

            while (cur != null)
            {
                max = Math.Max(max, cur.Value);
                min = Math.Min(min, cur.Value);
                cur = cur.Next;
            }
            return(max - min);
        }
Ejemplo n.º 5
0
        public static ForwardList <T> operator !(ForwardList <T> obj)
        {
            ForwardList <T> result = (ForwardList <T>)obj.Clone();

            Iterator <T> cur = result.First;

            while (cur != null)
            {
                cur = -cur;
                cur = cur.Next;
            }

            return(result);
        }
Ejemplo n.º 6
0
        public object Clone()
        {
            ForwardList <T> cloned = new ForwardList <T>();
            Iterator <T>    clonedCur = cloned.First, cur = First;

            while (cur != null)
            {
                clonedCur.Value = cur.Value;
                if (cur.Next != null)
                {
                    clonedCur.Next = new Iterator <T>(cur.Next.Value);
                }
                clonedCur = clonedCur.Next;
                cur       = cur.Next;
            }
            return(cloned);
        }
Ejemplo n.º 7
0
        public static ForwardList <T> operator +(ForwardList <T> left, ForwardList <T> right)
        {
            ForwardList <T> result = (ForwardList <T>)left.Clone();
            Iterator <T>    cur = result.First, rightCur = right.First;

            while (cur != null && rightCur != null)
            {
                cur.Next = new Iterator <T>(rightCur.Value, cur.Next);
                rightCur = rightCur.Next;
                cur      = cur.Next.Next;
            }

            cur = result.GetLast();
            while (rightCur != null)
            {
                cur.Next = new Iterator <T>(rightCur.Value);
                rightCur = rightCur.Next;
                cur      = cur.Next;
            }

            return(result);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            ForwardList <int> .Owner owner = new ForwardList <int> .Owner(DateTime.Now.Millisecond)
            {
                author  = "QuatreB",
                company = "Software Crew"
            };
            Console.WriteLine($"\t\tWho am I?\n\t\t{owner}\n");

            ForwardList <int> a = new ForwardList <int>(rand.Next(2, 5));
            ForwardList <int> b = new ForwardList <int>(rand.Next(2, 5));

            try
            {
                Console.WriteLine($" [A]\tOwner: {a.owner}\tCreation date: {a.creationDate}\n" + a);
                Console.WriteLine($" [B]\tOwner: {b.owner}\tCreation date: {b.creationDate}\n" + b);
                Console.WriteLine();

                Console.WriteLine(" [A + B] Объединение:\n" + (a + b));
                Console.WriteLine(" [A < B] Присоединение:\n" + (a < b));
                Console.WriteLine(" [A > B] Присоединение:\n" + (a > b));
                Console.WriteLine(" [A == B] Сравнение:\n\t" + (a == b));
                Console.WriteLine(" [A != B] Сравнение:\n\t" + (a != b));

                Console.WriteLine(" [!A] Инверсия:\n" + !a);
                Console.WriteLine(" [!B] Инверсия:\n" + !b);
            }
            catch (InvalidCastException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Data);
                Console.WriteLine(ex.StackTrace);
                Console.ForegroundColor = ConsoleColor.White;
            }

            ForwardList <Equipment> c = new ForwardList <Equipment>()
            {
                First = new Iterator <Equipment>
                {
                    Value = new Equipment()
                    {
                        somethingField    = 10,
                        SomethingProperty = "smth"
                    },
                },
            };

            c.Insert(new Equipment()
            {
                SomethingProperty = "property"
            });
            c.View();
            c.First.Value.SomethingMethod();
            Console.WriteLine();

            try
            {
                a.Insert(228); b.Insert(228);
                a.Insert(337); b.Insert(337);
                a.View(); b.View();
                Console.WriteLine();
                a.Extract(228); b.Extract(337);
                a.View(); b.View();
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }

            try
            {
                a.OutputToFile(new FileStream(Directory.GetCurrentDirectory() + @"\a.txt", FileMode.Create));
                b.InputFromFile(new FileStream(Directory.GetCurrentDirectory() + @"\a.txt", FileMode.Open));
            }
            finally
            {
                Console.WriteLine();
                a.View(); b.View();
                Console.WriteLine("[finally] Application was stopped!");
            }

            Console.ReadKey();
        }