public void test_addNode()
        {
            SingleLinkedList <int> test = new SingleLinkedList <int>();

            test.AddNode(1);
            test.AddNode(3);

            Assert.AreEqual(test.headNode.next.data, 3);
        }
        public void test_add_back_value()
        {
            SingleLinkedList <int> test = new SingleLinkedList <int>();

            test.AddNode(1);
            test.AddNode(2);
            test.InsertBack(3);

            Assert.AreEqual(test.currentNode.data, 3);
        }
        public void test_add_back()
        {
            SingleLinkedList <int> test = new SingleLinkedList <int>();

            test.AddNode(1);
            test.AddNode(2);
            test.InsertBack(3);

            Assert.AreEqual(test.headNode.data, 1);
        }
        public void test_last_one_data_infront()
        {
            SingleLinkedList <int> test = new SingleLinkedList <int>();

            test.AddNode(1);
            test.AddNode(3);
            test.AddNode(4);
            test.InsertFront(5);

            Assert.AreEqual(test.headNode.data, 5);
        }
        public void test_addNode_count()
        {
            SingleLinkedList <int> test = new SingleLinkedList <int>();

            test.AddNode(1);
            test.AddNode(3);
            test.AddNode(4);
            test.AddNode(5);

            Assert.AreEqual(test.Lenght, 4);
        }
예제 #6
0
        /// <summary>
        /// Using linked list to represent a number, add two numbers.
        /// </summary>
        /// <param name="a">number 1 as linked list</param>
        /// <param name="b">number 2 as linked list</param>
        /// <returns>result of addition</returns>
        public static SingleLinkedList <uint> AddListsAsNumbers(SingleLinkedList <uint> a, SingleLinkedList <uint> b)
        {
            SingleLinkedList <uint> result = new SingleLinkedList <uint>();
            SingleNode <uint>       p1     = a.Head;
            SingleNode <uint>       p2     = b.Head;

            uint vp = 0;

            while (p1 != null || p2 != null || vp != 0)
            {
                uint v1 = (p1 != null) ? p1.Value : 0;
                uint v2 = (p2 != null) ? p2.Value : 0;
                uint va = (v1 + v2 + vp) % 10;

                result.AddNode(va);

                vp = (v1 + v2 + vp) / 10;
                p1 = (p1 != null) ? p1.Next : null;
                p2 = (p2 != null) ? p2.Next : null;
            }

            return(result);
        }