Exemple #1
0
        private static void ExecuteCommands(GenericLinkedList <int> linkedList)
        {
            var numberOfCommands = int.Parse(Console.ReadLine());

            while (numberOfCommands > 0)
            {
                var command = Console.ReadLine().Split();
                var number  = int.Parse(command[1]);

                switch (command[0])
                {
                case "Add":
                    linkedList.Add(number);
                    break;

                case "Remove":
                    linkedList.Remove(number);
                    break;

                default:
                    break;
                }
                numberOfCommands--;
            }
        }
 public void Test_GenericLinkedList_Method_Remove_SuccessOnlyLastIndex()
 {
     linkedList = new GenericLinkedList <int>();
     linkedList.PushLast(zeroInt);
     linkedList.PushLast(oneInt);
     linkedList.PushLast(negOneInt);
     node = linkedList.Remove(2);
     Assert.IsNotNull(node);
     Assert.AreEqual(negOneInt, node.Data);
     Assert.IsNull(node.Next);
     Assert.IsNull(node.Previous);
     Assert.AreEqual(zeroInt, linkedList.FirstNode.Data);
     Assert.AreEqual(oneInt, linkedList.LastNode.Data);
     Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode.Previous);
     Assert.AreEqual(linkedList.LastNode, linkedList.FirstNode.Next);
     node = linkedList.Remove(1);
     Assert.IsNotNull(node);
     Assert.AreEqual(oneInt, node.Data);
     Assert.IsNull(node.Next);
     Assert.IsNull(node.Previous);
     Assert.AreEqual(zeroInt, linkedList.FirstNode.Data);
     Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode);
     node = linkedList.Remove(0);
     Assert.IsNotNull(node);
     Assert.AreEqual(zeroInt, node.Data);
     Assert.IsNull(node.Next);
     Assert.IsNull(node.Previous);
     Assert.IsNull(linkedList.FirstNode);
     Assert.IsNull(linkedList.LastNode);
 }
        public void Test_GenericLinkedList_Method_Dequeue_Success()
        {
            linkedList = new GenericLinkedList <int>();
            linkedList.Enqueue(zeroInt);
            linkedList.Enqueue(oneInt);
            linkedList.Enqueue(negOneInt);

            // Test dequeue on list with three items.
            node = linkedList.Dequeue();
            Assert.IsNotNull(node);
            Assert.AreEqual(oneInt, linkedList.FirstNode.Data);
            Assert.AreEqual(negOneInt, linkedList.LastNode.Data);
            Assert.IsNull(linkedList.FirstNode.Previous);
            Assert.IsNull(linkedList.LastNode.Next);

            // Test dequeue on list with two items.
            node = linkedList.Dequeue();
            Assert.IsNotNull(node);
            Assert.AreEqual(negOneInt, linkedList.FirstNode.Data);
            Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode);
            Assert.IsNull(linkedList.FirstNode.Previous);
            Assert.IsNull(linkedList.LastNode.Next);

            // Test dequeue on list with one item.
            node = linkedList.Dequeue();
            Assert.IsNotNull(node);
            Assert.IsNull(linkedList.FirstNode);
            Assert.IsNull(linkedList.LastNode);

            // Tested on 1, 1+1, and 1+2 items. Should work on all further n+1 values.
        }
        public void Test_GenericLinkedList_Method_Enqueue_Success()
        {
            linkedList = new GenericLinkedList <int>();

            // Test enqueue to empty list.
            linkedList.Enqueue(zeroInt);
            Assert.AreEqual(zeroInt, linkedList.FirstNode.Data);
            Assert.AreEqual(zeroInt, linkedList.LastNode.Data);
            Assert.IsNull(linkedList.FirstNode.Previous);
            Assert.IsNull(linkedList.LastNode.Next);

            // Test enqueue to list with one item.
            linkedList.Enqueue(oneInt);
            Assert.AreEqual(oneInt, linkedList.LastNode.Data);
            Assert.AreEqual(zeroInt, linkedList.FirstNode.Data);
            Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode.Previous);
            Assert.IsNull(linkedList.FirstNode.Previous);
            Assert.IsNull(linkedList.LastNode.Next);

            // Test enqueue to list with two items.
            linkedList.Enqueue(negOneInt);
            Assert.AreEqual(negOneInt, linkedList.LastNode.Data);
            Assert.AreEqual(oneInt, linkedList.LastNode.Previous.Data);
            Assert.AreEqual(zeroInt, linkedList.LastNode.Previous.Previous.Data);
            Assert.AreEqual(linkedList.FirstNode.Next, linkedList.LastNode.Previous);
            Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode.Previous.Previous);
            Assert.IsNull(linkedList.FirstNode.Previous);
            Assert.IsNull(linkedList.LastNode.Next);

            // Tested on null, n, and n+1 items. Should work on all further values.
        }
Exemple #5
0
        public static void Main()
        {
            var linkedList = new GenericLinkedList <int>();

            ExecuteCommands(linkedList);
            PrinntResult(linkedList);
        }
Exemple #6
0
 static void Main(string[] args)
 {
     GenericLinkedList<System.Object> gll = new GenericLinkedList<System.Object>();
     gll.Add(12);
     gll.Add("string");
     gll.Add(false);
     gll.DisplayNodes();
 }
 public void Test_GenericLinkedList_Constructor()
 {
     linkedList = new GenericLinkedList <int>();
     Assert.IsNotNull(linkedList);
     Assert.IsNull(linkedList.CurrentNode);
     Assert.IsNull(linkedList.FirstNode);
     Assert.IsNull(linkedList.LastNode);
 }
 public void AddToTopTest()
 {
     GenericLinkedList<int> list = new GenericLinkedList<int>();
     list.AddToTop(1);
     list.AddToTop(2);
     string result = list.ToString();
     Assert.AreNotEqual(string.Empty, result);
     Assert.AreEqual("2, 1", result);
 }
 public void Test_GenericLinkedList_Method_Retrieve_IndexTooLow()
 {
     linkedList = new GenericLinkedList <int>();
     node       = linkedList.Retrieve(0);
     Assert.IsNull(node);
     linkedList.PushLast(zeroInt);
     node = linkedList.Retrieve(-1);
     Assert.IsNull(node);
 }
Exemple #10
0
        public void AddToTopTest()
        {
            GenericLinkedList <int> list = new GenericLinkedList <int>();

            list.AddToTop(1);
            list.AddToTop(2);
            string result = list.ToString();

            Assert.AreNotEqual(string.Empty, result);
            Assert.AreEqual("2, 1", result);
        }
 /// <summary>
 /// Displays output of all items inside linked list.
 /// </summary>
 /// <param name="allItemsOutput">Linked List filled with strings from database information.</param>
 public void DisplayAllListItems(GenericLinkedList<string> allItemsOutput)
 {
     Console.WriteLine();
     int indexInt = 0;
     while (indexInt < allItemsOutput.Length)
     {
         Console.WriteLine(allItemsOutput.Retrieve(1).Data);
         allItemsOutput.DeQueue();
         indexInt++;
     }
 }
        public void Test_GenericLinkedList_Method_Remove_IndexTooLow()
        {
            linkedList = new GenericLinkedList <int>();
            node       = linkedList.Remove(0);
            Assert.IsNull(node);
            linkedList.PushLast(0);
            node = linkedList.Remove(-1);
            Assert.IsNull(node);

            // Tested for n and n+1 items. Should be valid for all further values.
        }
 public void Test_GenericLinkedList_Method_Add_BadIndexEmptyList()
 {
     linkedList = new GenericLinkedList <int>();
     testBool   = linkedList.Add(zeroInt, 1);
     Assert.IsFalse(testBool);
     Assert.IsNull(linkedList.FirstNode);
     Assert.IsNull(linkedList.LastNode);
     testBool = linkedList.Add(zeroInt, -1);
     Assert.IsFalse(testBool);
     Assert.IsNull(linkedList.FirstNode);
     Assert.IsNull(linkedList.LastNode);
 }
        public void ReadAtTest()
        {
            GenericLinkedList<int> list = new GenericLinkedList<int>();
            list.AddToEnd(1);
            list.AddToEnd(2);
            list.AddToEnd(3);
            string output = list.ToString();
            Assert.AreNotEqual(string.Empty, output);
            Assert.AreEqual("1, 2, 3", output);

            int result = list.ReadAt(2);
            Assert.AreEqual(2, result);
        }
 public void Test_GenericLinkedList_Method_Retrieve_Success()
 {
     linkedList = new GenericLinkedList <int>();
     linkedList.PushLast(zeroInt);
     linkedList.PushLast(oneInt);
     linkedList.PushLast(negOneInt);
     node = linkedList.Retrieve(0);
     Assert.AreEqual(zeroInt, node.Data);
     node = linkedList.Retrieve(1);
     Assert.AreEqual(oneInt, node.Data);
     node = linkedList.Retrieve(2);
     Assert.AreEqual(negOneInt, node.Data);
 }
 public void Test_GenericLinkedList_Method_Add_BadIndex()
 {
     linkedList = new GenericLinkedList <int>();
     testBool   = linkedList.Add(zeroInt, 0);
     Assert.IsTrue(testBool);
     testBool = linkedList.Add(oneInt, 1);
     Assert.IsTrue(testBool);
     testBool = linkedList.Add(negOneInt, 2);
     Assert.IsTrue(testBool);
     testBool = linkedList.Add(zeroInt, 4);
     Assert.IsFalse(testBool);
     testBool = linkedList.Add(zeroInt, -1);
     Assert.IsFalse(testBool);
 }
Exemple #17
0
        public void RemoveAtFirstWhenThereIsOneNodeTest()
        {
            GenericLinkedList <int> list = new GenericLinkedList <int>();

            list.AddToEnd(1);
            string result = list.ToString();

            Assert.AreNotEqual(string.Empty, result);
            Assert.AreEqual("1", result);

            list.RemoveAt(1);

            result = list.ToString();
            Assert.AreEqual(string.Empty, result);
        }
        public void RemoveAtFirstTest()
        {
            GenericLinkedList<int> list = new GenericLinkedList<int>();
            list.AddToEnd(1);
            list.AddToEnd(2);
            string result = list.ToString();
            Assert.AreNotEqual(string.Empty, result);
            Assert.AreEqual("1, 2", result);

            list.RemoveAt(1);

            result = list.ToString();
            Assert.AreNotEqual(string.Empty, result);
            Assert.AreEqual("2", result);
        }
Exemple #19
0
        public void ReadAtTest()
        {
            GenericLinkedList <int> list = new GenericLinkedList <int>();

            list.AddToEnd(1);
            list.AddToEnd(2);
            list.AddToEnd(3);
            string output = list.ToString();

            Assert.AreNotEqual(string.Empty, output);
            Assert.AreEqual("1, 2, 3", output);

            int result = list.ReadAt(2);

            Assert.AreEqual(2, result);
        }
Exemple #20
0
        public void RemoveAtLastTest()
        {
            GenericLinkedList <int> list = new GenericLinkedList <int>();

            list.AddToEnd(1);
            list.AddToEnd(2);
            string result = list.ToString();

            Assert.AreNotEqual(string.Empty, result);
            Assert.AreEqual("1, 2", result);

            list.RemoveAt(2);

            result = list.ToString();
            Assert.AreNotEqual(string.Empty, result);
            Assert.AreEqual("1", result);
        }
Exemple #21
0
        static void Main(string[] args)
        {
            GenericLinkedList <int> linkedListOfNumbers = new GenericLinkedList <int>();

            for (int i = 0; i < 5; i++)
            {
                linkedListOfNumbers.Add(i);
            }

            foreach (var number in linkedListOfNumbers)
            {
                Console.WriteLine(number);
            }


            List <string> stringlist = new List <string>();
        }
        public void Test_GenericLinkedList_Method_CompareTo()
        {
            GenericLinkedList <string> linkedList1 = new GenericLinkedList <string>();
            GenericLinkedList <string> linkedList2 = new GenericLinkedList <string>();

            linkedList1.PushLast("Cat");
            linkedList2.PushLast("Cat");
            int compareValue = linkedList1.CompareTo(linkedList2);

            Assert.AreEqual(0, compareValue);

            linkedList2.PushLast("Dog");
            compareValue = linkedList1.CompareTo(linkedList2);
            Assert.AreEqual(-1, compareValue);
            compareValue = linkedList2.CompareTo(linkedList1);
            Assert.AreEqual(1, compareValue);
        }
Exemple #23
0
        /// <summary>
        /// Initializes linked list of transaction occurances.
        /// </summary>
        private void InitializeLinkedList()
        {
            dateProcessed = dateStart;
            DateTime tempDateEnd = dateEnd;

            transactionList = new GenericLinkedList <Transaction>();
            transactionList.PushFirst(new Transaction(paymentFrom, paymentTo, dateProcessed));

            if (tempDateEnd == DateTime.MinValue)
            {
                tempDateEnd = DateTime.Today.AddMonths(12);
            }

            while (dateProcessed.CompareTo(tempDateEnd) < 0)
            {
                dateProcessed = dateProcessed.AddDays(frequency);
                transactionList.PushLast(new Transaction(paymentFrom, paymentTo, dateProcessed));
            }
            lastCompletedTransactionIndex = -1;
        }
 public void Test_GenericLinkedList_Method_Add_SuccessOnlyFirstIndex()
 {
     linkedList = new GenericLinkedList <int>();
     testBool   = linkedList.Add(zeroInt, 0);
     Assert.IsTrue(testBool);
     Assert.AreEqual(zeroInt, linkedList.FirstNode.Data);
     Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode);
     testBool = linkedList.Add(oneInt, 0);
     Assert.IsTrue(testBool);
     Assert.AreEqual(oneInt, linkedList.FirstNode.Data);
     Assert.AreEqual(zeroInt, linkedList.LastNode.Data);
     Assert.AreEqual(linkedList.FirstNode, linkedList.LastNode.Previous);
     Assert.AreEqual(linkedList.LastNode, linkedList.FirstNode.Next);
     testBool = linkedList.Add(negOneInt, 0);
     Assert.IsTrue(testBool);
     Assert.AreEqual(negOneInt, linkedList.FirstNode.Data);
     Assert.AreEqual(oneInt, linkedList.FirstNode.Next.Data);
     Assert.AreEqual(zeroInt, linkedList.FirstNode.Next.Next.Data);
     Assert.AreEqual(zeroInt, linkedList.LastNode.Data);
     Assert.AreEqual(oneInt, linkedList.LastNode.Previous.Data);
     Assert.AreEqual(negOneInt, linkedList.LastNode.Previous.Previous.Data);
 }
Exemple #25
0
 private static void PrinntResult(GenericLinkedList <int> linkedList)
 {
     Console.WriteLine(linkedList.Count);
     Console.WriteLine(string.Join(" ", linkedList));
 }
Exemple #26
0
        static void Main(string[] args)
        {
            string line1 = Console.ReadLine();
            int    N     = Convert.ToInt32(line1.Split()[0]);
            int    Q     = Convert.ToInt32(line1.Split()[1]);

            List <Circle> circles = new List <Circle>();

            for (int i = 0; i < N; i++)
            {
                Circle c;
                string line2 = Console.ReadLine();
                c.x = Convert.ToInt32(line2.Split()[0]);
                c.y = Convert.ToInt32(line2.Split()[1]);
                c.r = Convert.ToInt32(line2.Split()[2]);
                circles.Add(c);
            }

            List <Rect> rectangles = new List <Rect>();

            for (int i = 0; i < Q; i++)
            {
                Rect   r;
                string line3 = Console.ReadLine();
                r.x1 = Convert.ToInt32(line3.Split()[0]);
                r.y1 = Convert.ToInt32(line3.Split()[1]);
                r.x2 = Convert.ToInt32(line3.Split()[2]);
                r.y2 = Convert.ToInt32(line3.Split()[3]);
                rectangles.Add(r);
            }

            foreach (var rectangle in rectangles)
            {
                Console.WriteLine(CalculateAreaInsideRect(circles, rectangle));
            }
            int[]  states  = { 0, 1, 0, 0, 1, 0, 1, 0 };
            string binary1 = "";

            for (int i = 0; i < states.Length; i++)
            {
                binary1 += states[i].ToString();
            }
            int    decimal1 = Convert.ToInt32(binary1, 2);
            string result   = binary1;

            for (int k = 0; k < 2; k++)
            {
                int decimal2 = decimal1 << 2;

                int resultDecimal = decimal1 ^ decimal2;

                resultDecimal = resultDecimal >> 1;
                result        = Convert.ToString(resultDecimal, 2);


                for (int i = 0; i < 8 - result.Length; i++)
                {
                    result = "0" + result;
                }

                result   = result.Substring(result.Length - 8);
                decimal1 = Convert.ToInt32(result, 2);
            }

            int[] FinalStates = new int[8];
            for (int i = 0; i < result.Length; i++)
            {
                FinalStates[i] = Convert.ToInt32(result[i] - 48);
            }

            int [] arr = new int[] { 8, 10, 4, 10, 0, 45, 102, 1, 45, 11, 12, 12, 3, 899, 76, 98, 33 };
            //SortingAlgorithm.MergeSort(arr,0,arr.Length-1);
            SortingAlgorithm.HeapSort(arr);

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }

            RBTree rbTree = new RBTree(1);

            rbTree.InsertNode(2);
            rbTree.InsertNode(3);
            rbTree.InsertNode(4);
            rbTree.InsertNode(5);
            rbTree.InsertNode(6);
            rbTree.InsertNode(7);
            rbTree.InsertNode(8);

            rbTree.LevelOrderTraversal();

            rbTree.ROOT = rbTree.DeleteNode(rbTree.ROOT, 1);
            rbTree.ROOT = rbTree.DeleteNode(rbTree.ROOT, 3);
            Console.WriteLine();
            rbTree.LevelOrderTraversal();
            rbTree.ROOT = rbTree.DeleteNode(rbTree.ROOT, 7);
            Console.WriteLine();
            rbTree.LevelOrderTraversal();

            AVLTree avlTree = new AVLTree(1);

            avlTree.InsertNode(2);
            avlTree.InsertNode(3);
            avlTree.InsertNode(4);
            avlTree.InsertNode(5);
            avlTree.InsertNode(6);
            avlTree.InsertNode(7);
            avlTree.InsertNode(8);

            avlTree.LevelOrderTraversal();

            avlTree.ROOT = avlTree.DeleteNode(avlTree.ROOT, 1);
            avlTree.ROOT = avlTree.DeleteNode(avlTree.ROOT, 3);
            Console.WriteLine();
            avlTree.LevelOrderTraversal();

            BinaryTree <int> bTree = new BinaryTree <int>(1);

            bTree.AddNode(bTree.ROOT, 2, 2);
            bTree.AddNode(bTree.ROOT, 3, 3);
            bTree.AddNode(bTree.ROOT, 5, 4);
            bTree.AddNode(bTree.ROOT, 7, 5);
            bTree.AddNode(bTree.ROOT, 11, 6);

            bTree.LevelOrderTraversal();

            CircularArrayQueue <int> objq = new CircularArrayQueue <int>();

            objq.Enqueue(1);
            objq.Enqueue(2);
            objq.Enqueue(3);
            objq.Enqueue(6);
            objq.Dequeue();
            objq.Enqueue(4);
            objq.Dequeue();
            objq.ReadAll();

            Console.WriteLine(ProblemsOnStacks.MaxSpan(new int[] { 100, 60, 80, 90, 70, 75, 11, 120 }));

            Console.WriteLine(ProblemsOnStacks.InfixToPostfix("a*b+c-(d+f)"));

            RandomPtrLinkedList <int> obj3 = new RandomPtrLinkedList <int>();

            obj3.AddEnd(1);
            obj3.AddEnd(2);
            obj3.AddEnd(3);
            obj3.AddEnd(4);
            obj3.AddEnd(5);
            obj3.AddEnd(6);
            obj3.AddEnd(7);
            obj3.AddEnd(8);
            obj3.AddEnd(9);

            obj3.SetRandomNodes();
            obj3.ReadAll();

            RandomPtrLinkedList <int> obj3Clone = new RandomPtrLinkedList <int>();

            obj3Clone.HEAD = ProblemsOnLinkedList <int> .CloneRandomPtrList(obj3.HEAD);

            Console.WriteLine("Old List : ");
            obj3.ReadAll();
            Console.WriteLine("Cloned List : ");
            obj3Clone.ReadAll();

            GenericLinkedList <int> obj = new GenericLinkedList <int>();

            obj.AddStart(78);
            obj.AddStart(89);
            obj.AddEnd(100);
            obj.AddStart(3);
            obj.AddStart(123);
            obj.RemoveEnd();
            obj.AddEnd(800);
            obj.RemoveStart();


            obj.ReadAll();

            GenericLinkedList <int> obj2 = new GenericLinkedList <int>();

            obj2.AddEnd(1);
            obj2.AddEnd(2);
            obj2.AddEnd(3);
            obj2.AddEnd(4);
            obj2.AddEnd(5);
            obj2.AddEnd(6);
            obj2.AddEnd(7);
            obj2.AddEnd(8);
            obj2.AddEnd(9);

            obj2.ReadAll();

            obj2.HEAD = ProblemsOnLinkedList <int> .ReverseInChunks(obj2.HEAD, 5);

            obj2.ReadAll();

            GenericLinkedList <char> obj1 = new GenericLinkedList <char>();

            obj1.AddStart('n');
            obj1.AddStart('n');
            obj1.AddEnd('i');
            obj1.AddEnd('t');
            obj1.AddEnd('t');
            obj1.AddEnd('i');
            obj1.AddEnd('n');
            obj1.AddEnd('n');

            obj1.ReadAll();

            if (ProblemsOnLinkedList <char> .IsPalindrome(obj1.HEAD))
            {
                Console.WriteLine("Palindrome ");
            }
            else
            {
                Console.WriteLine("Not Palindrome ");
            }

            obj1.ReadAll();

            obj.HEAD = ProblemsOnLinkedList <int> .ReverseList(obj.HEAD);

            obj.ReadAll();

            Console.WriteLine("The nth node is : " + ProblemsOnLinkedList <int> .ReturnNthNodeFromEnd(obj.HEAD, 2).data);

            Console.ReadLine();
        }
        /// <summary>
        /// Get The Print String Array For All Items
        /// </summary>
        /// <returns>Linked list of all items information.</returns>
        public GenericLinkedList<string> GetStringListForAllItems()
        {
            //Create a linked list to hold all of the printed strings
            GenericLinkedList<string> beveragesList = new GenericLinkedList<string>();

            // Loops through list and adds each to list.
            foreach (Beverage beverage in beverageEntities.Beverages)
            {
                beveragesList.Enqueue(UserInterface.ItemToString(beverage));
            }

            //Return the List of item strings
            return beveragesList;
        }
Exemple #28
0
 public void ClearQueue()
 {
     queue = null;
     list  = null;
 }
 public void Test_GenericLinkedList_Method_Dequeue_EmptyList()
 {
     linkedList = new GenericLinkedList <int>();
     node       = linkedList.Dequeue();
 }
Exemple #30
0
        static void Main(string[] args)
        {
            //Define a new linked list to use
            MyLinkedList myLinkedList = new MyLinkedList();

            //Add a bunch of stuff to it
            myLinkedList.Add("first");
            myLinkedList.Add("second");
            myLinkedList.Add("third");
            myLinkedList.Add("fourth");

            //Loop through with this differently looking for loop to output
            //In here, the first part is initalization: Setting x to the Head
            //the second part is the test: If x != null, keep going
            //The last part is: Set the current x to x's next porinter. (The next in the list)
            for (Node x = myLinkedList.Head; x != null; x = x.Next)
            {
                Console.WriteLine(x.Data);
            }

            //Couple of blank lines
            Console.WriteLine();
            Console.WriteLine();

            //Print out the 2nd one
            Node nodeINeed = myLinkedList.Retrive(2);
            Console.WriteLine(nodeINeed.Data);

            //Print out the 2nd one again in one statement
            Console.WriteLine(myLinkedList.Retrive(2).Data);

            //Couple of blank lines
            Console.WriteLine();
            Console.WriteLine();

            //Delete the 2nd element in the list
            myLinkedList.Delete(2);
            //Delete the new 2nd element in the list. Was 3rd before previous delete
            myLinkedList.Delete(2);

            for (Node x = myLinkedList.Head; x != null; x = x.Next)
            {
                Console.WriteLine(x.Data);
            }

            //Couple of blank lines
            Console.WriteLine();
            Console.WriteLine();

            //Add two new ones to the list
            myLinkedList.Add("fifth");
            myLinkedList.Add("sixth");

            //Print the list one last time
            for (Node x = myLinkedList.Head; x != null; x = x.Next)
            {
                Console.WriteLine(x.Data);
            }

            Console.WriteLine("***************************************");
            Console.WriteLine("***************************************");

            //A generic linked list that sends in the type that we would like to use
            //This one will behave exactly like the one used above since it is taking a
            //string.
            GenericLinkedList<string> myGenericLinkedList = new GenericLinkedList<string>();

            //Some other linked lists that can use the generic one. One of them is of type
            //integer, and the other is of type Object
            GenericLinkedList<int> myOtherGenericLinkedLIst = new GenericLinkedList<int>();
            GenericLinkedList<Object> myObjectGenericLinkedList = new GenericLinkedList<object>();

            //Use the generic string one to do the same work as above
            //Add a bunch of stuff to it
            myGenericLinkedList.Add("first");
            myGenericLinkedList.Add("second");
            myGenericLinkedList.Add("third");
            myGenericLinkedList.Add("fourth");

            //Loop through with this differently looking for loop to output
            //In here, the first part is initalization: Setting x to the Head
            //the second part is the test: If x != null, keep going
            //The last part is: Set the current x to x's next porinter. (The next in the list)
            for (GenericNode<string> x = myGenericLinkedList.Head; x != null; x = x.Next)
            {
                Console.WriteLine(x.Data);
            }
        }
 public void Test_GenericLinkedList_Method_PopLast_EmptyList()
 {
     linkedList = new GenericLinkedList <int>();
     node       = linkedList.PopLast();
 }
Exemple #32
0
        public void CanaryTest()
        {
            GenericLinkedList <int> result = new GenericLinkedList <int>();

            Assert.AreNotEqual(null, result);
        }
        /// <summary>
        /// Modified bucket sort.
        /// </summary>
        public void SortBucket()
        {
            // Create stacks for each droid type.
            GenericLinkedList<IDroid> Protocol_Stack = new GenericLinkedList<IDroid>();
            GenericLinkedList<IDroid> Utility_Stack = new GenericLinkedList<IDroid>();
            GenericLinkedList<IDroid> Janitor_Stack = new GenericLinkedList<IDroid>();
            GenericLinkedList<IDroid> Astromech_Stack = new GenericLinkedList<IDroid>();
            // Create single queue for droids.
            GenericLinkedList<IDroid> Droid_Queue = new GenericLinkedList<IDroid>();

            // Go through entire current collection and add droids to appropriate spots.
            indexInt = 0;
            while (indexInt < droidListSizeInt)
            {
                switch (((Droid)droidCollection[indexInt]).droidTypeString)
                {
                    case "Protocol":
                        Protocol_Stack.Push(droidCollection[indexInt]);
                        break;
                    case "Utility":
                        Utility_Stack.Push(droidCollection[indexInt]);
                        break;
                    case "Janitor":
                        Janitor_Stack.Push(droidCollection[indexInt]);
                        break;
                    case "Astromech":
                        Astromech_Stack.Push(droidCollection[indexInt]);
                        break;
                }
                indexInt++;
            }

            // Technically not needed, but added to be able to see that the list is empty before being popped off the queue. For debugging purposes.
            //Remove in final version.
            indexInt = 0;
            while (indexInt < droidListSizeInt)
            {
                droidCollection[indexInt] = null;
                indexInt++;
            }

            // Take droids off stacks and put into queue.
            while (Astromech_Stack.HeadNode != null)
            {
                Droid_Queue.Enqueue(Astromech_Stack.HeadNode.Data);
                Astromech_Stack.Pop();
            }

            while (Janitor_Stack.HeadNode != null)
            {
                Droid_Queue.Enqueue(Janitor_Stack.HeadNode.Data);
                Janitor_Stack.Pop();
            }

            while (Utility_Stack.HeadNode != null)
            {
                Droid_Queue.Enqueue(Utility_Stack.HeadNode.Data);
                Utility_Stack.Pop();
            }

            while (Protocol_Stack.HeadNode != null)
            {
                Droid_Queue.Enqueue(Protocol_Stack.HeadNode.Data);
                Protocol_Stack.Pop();
            }

            // Take droids out of queue and back into array.
            indexInt = 0;
            while (Droid_Queue.HeadNode != null)
            {
                droidCollection[indexInt] = Droid_Queue.HeadNode.Data;
                Droid_Queue.DeQueue();
                indexInt++;
            }
        }
 public void CanaryTest()
 {
     GenericLinkedList<int> result = new GenericLinkedList<int>();
     Assert.AreNotEqual(null, result);
 }