コード例 #1
0
        // RemoveObject - remove an object from the list
        public void RemoveObject(LLNode <T> currentNode)
        {
            // get the current node's neighbors
            LLNode <T> previousNode = currentNode.backward;
            LLNode <T> nextNode     = currentNode.forward;

            // remove the current object's pointers
            currentNode.forward = currentNode.backward = null;

            // now... if this was the last element in the list
            if (head == currentNode && tail == currentNode)
            {
                head = tail = null;
                return;
            }

            // ok, if this node is in the middle...
            if (head != currentNode && tail != currentNode)
            {
                previousNode.forward = nextNode;
                nextNode.backward    = previousNode;
                return;
            }

            // at the front of the list?
            if (head == currentNode && tail != currentNode)
            {
                head = nextNode;
                nextNode.backward = null;
                return;
            }

            // must be at the end of the list
            tail = previousNode;
            previousNode.forward = null;
        }