Example #1
0
 public void Add(LinkedListElement l)
 {
     if (m_next == null)
     {
         m_next = l;
         m_next.m_previous = this;
     }
     else
     {
         m_next.m_previous = l;
         l.m_next = m_next;
         l.m_previous = this;
         m_next = l;
     }
 }
Example #2
0
 public LinkedListElement Remove()
 {
     if (m_previous == null && m_next == null)
     {
         
     }
     else if (m_next == null)
     {
         m_previous.m_next = null;
     }
     else if (m_previous == null)
     {
         m_next.m_previous = null;
     }
     else
     {
         m_next.m_previous = m_previous;
         m_previous.m_next = m_next;
     }
     LinkedListElement n = m_next;
     m_next = null;
     m_previous = null;
     return n;
 }
Example #3
0
        private static LinkedListElement<int> SumOfTwoNode(LinkedListElement<int> list1CurrentNode, LinkedListElement<int> list2CurrentNode, int carry)
        {
            if (list1CurrentNode == null && list2CurrentNode == null) return null;
            if (list1CurrentNode != null && list2CurrentNode != null)
            {
                var currentSumValue = list1CurrentNode.Data + list2CurrentNode.Data + carry;
                carry = currentSumValue >= 10 ? 1 : 0;
                return new LinkedListElement<int>()
                {
                    Data = currentSumValue % 10,
                    Next =
                        SumOfTwoNode(list1CurrentNode.Next, list2CurrentNode.Next, carry)
                };

            }
            if (list1CurrentNode != null)
            {
                var currentSumValue = list1CurrentNode.Data + carry;
                carry = currentSumValue >= 10 ? 1 : 0;
                return new LinkedListElement<int>()
                {
                    Data = currentSumValue % 10,
                    Next = SumOfTwoNode(list1CurrentNode.Next, null, carry)
                };
            }
            else
            {
                var currentSumValue = list2CurrentNode.Data + carry;
                carry = currentSumValue >= 10 ? 1 : 0;
                return new LinkedListElement<int>()
                {
                    Data = currentSumValue % 10,
                    Next = SumOfTwoNode(null, list2CurrentNode.Next, carry)
                };
            }
        }