Esempio n. 1
0
        static void Main(string[] args)
        {
            DoublyLinkedList <Minion> minion = new DoublyLinkedList <Minion>();

            {
                minion.Add(new Minion(1, "Kevin", 14, 3));
                minion.Add(new Minion(2, "Bob", 23, 2));
                minion.Add(new Minion(3, "Stuart", 21, 1));
            }
            minion.AddFirst(new Minion(4, "Mark", 20, 4));
            foreach (var item in minion)
            {
                Console.WriteLine(item);
            }

            minion.Remove(2);

            foreach (var t in minion.BackEnumerator())
            {
                Console.WriteLine(t);
            }
        }
        static void Main(string[] args)
        {
            var slist = new SinglyLinkedList <int>();

            slist.Add(10);
            slist.Add(20);
            slist.Insert(2, 2);
            slist.Insert(2, 5);
            //slist.Remove(2);
            //slist.Insert(2, 3);

            slist.Add(0);
            slist.Add(1);
            slist.Add(2);
            Console.WriteLine("get index 1: " + slist.Get(1));
            //slist.Remove(2);
            //slist.Get(1);
            //slist.Remove(1);
            //slist.Get(0);
            //slist.Remove(0);

            var currentSItem = slist.First;

            while (currentSItem != null)
            {
                Console.WriteLine(currentSItem.Data);

                currentSItem = currentSItem.Next;
            }

            Console.WriteLine("Max index: " + slist.GetMaxIndex());
            Console.WriteLine("Max: " + slist.GetMax());
            Console.WriteLine("Total sum: " + slist.CumulatieveSum(slist.GetMaxIndex()));
            Console.WriteLine("Max recursive: " + slist.GetMaxRecursive());

            Console.WriteLine("next list");

            var dlist = new DoublyLinkedList <int>();

            /*dlist.Add(1);
             * dlist.Add(8);
             * dlist.Add(2);
             * dlist.Add(6);
             * dlist.Add(7);
             * dlist.Insert(2, 2);
             * dlist.Insert(2, 5);
             * dlist.Remove(2);
             * dlist.Insert(2, 3);*/

            dlist.Add(3);
            dlist.Add(2);
            dlist.Add(1);
            dlist.Add(3);
            dlist.Add(2);
            dlist.Add(1);

            var currentDItem = dlist.First;

            while (currentDItem != null)
            {
                Console.WriteLine(currentDItem.Data);

                currentDItem = currentDItem.Next;
            }

            Console.WriteLine("list ordered");

            dlist.InsertionSort();

            currentDItem = dlist.First;
            while (currentDItem != null)
            {
                Console.WriteLine(currentDItem.Data);

                currentDItem = currentDItem.Next;
            }

            Console.WriteLine("reverse index 2 and 5");

            dlist.Swap(2, 5);

            currentDItem = dlist.First;
            while (currentDItem != null)
            {
                Console.WriteLine(currentDItem.Data);

                currentDItem = currentDItem.Next;
            }

            Console.ReadKey();
        }