Esempio n. 1
0
        /// <summary>
        /// Сортує черг, методом бульбашки
        /// </summary>
        /// <param name="Q">Черга який сортується</param>
        public static void Sort <V>(MyQueue <V> Q) where V : IComparable <V>
        {
            Node <V> ptr1 = Q.Front;
            Node <V> ptr2;

            while (ptr1 != null)
            {
                ptr2 = Q.Front;
                while (ptr2.Next != null)
                {
                    if (ptr2.Data.CompareTo(ptr2.Next.Data) > 0)
                    {
                        var tmp = ptr2.Next;
                        Node <T> .Swap(ptr2, tmp);
                    }
                    ptr2 = ptr2.Next;
                }
                ptr1 = ptr1.Next;
            }
        }
        static void Main(string[] args)
        {
            MyLinkedList <int> L1 = new MyLinkedList <int>();
            MyLinkedList <int> L2 = new MyLinkedList <int>();

            L1.AddAtFront(2);
            L1.AddAtEnd(7);
            L1.AddAtFront(2);
            L1.AddAtEnd(2);
            L1.Print();
            L1.DeleteNode(7);
            L1.Print();
            L2.Clone(L1);
            L2.Print();
            MyLinkedList <int> L3 = L1 + L2;

            L3.Print();
            MyLinkedList <int> .Sort(L3);

            L3.Print();
            MyLinkedList <int> L4 = new MyLinkedList <int>(3, 6, 2, 4);

            foreach (var item in L4)
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine();
            MyStack <int> S1 = new MyStack <int>();

            S1.Push(6);
            S1.Push(3);
            S1.Print();
            MyStack <int> S2 = new MyStack <int>();

            S2.Clone(S1);
            S2.Print();
            MyStack <int> S3 = S1 + S2;

            S3.Print();
            MyStack <int> .Sort(S3);

            S3.Print();
            MyQueue <int> Q1 = new MyQueue <int>();

            Q1.Enqueue(3);
            Q1.Enqueue(2);
            Q1.Print();
            MyQueue <int> Q2 = new MyQueue <int>();

            Q2.Clone(Q1);
            Q2.Print();
            MyQueue <int> Q3 = Q1 + Q2;

            Q3.Print();
            MyQueue <int> .Sort(Q3);

            Q3.Print();
            int[] arr = Enumerable.Range(1, 5).ToArray();
            MyLinkedList <int> list = (MyLinkedList <int>)arr;
            MyLinkedList <int> l    = new MyLinkedList <int>(3, 4, 7, 2);
            MyQueue <int>      q    = (MyQueue <int>)arr;

            try
            {
                q.Dequeue();
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadLine();
        }