Beispiel #1
0
        /// <summary>
        /// Add element to linkedList
        /// Duplicit values are allowed!
        /// </summary>
        /// <param name="node">The node we want to add</param>
        public void AddElement(MyNode node)
        {
            if (node.GetParent() != null)
            {
                node.GetParent().GetChildrenLinkedList().DeleteElement(node);
            }

            if (representant == null)
            {
                representant = node;
                node.ResetNode();
            }
            else
            {
                // Swap pointers
                node.SetRightNode(representant);
                node.SetLeftNode(representant.GetLeftNode());
                representant.SetLeftNode(node);
                node.GetLeftNode().SetRightNode(node);
            }

            countElements++;
        }