예제 #1
0
        public void Del(int index)
        {
            DoublyNode <T> inode = GetNode(index);

            inode.Prev.Next = inode.Next;
            inode.Next.Prev = inode.Prev;
            if (index == 0)
            {
                _linkHead = inode.Next;
            }

            _count--;
        }
예제 #2
0
        public void AppendEnd(T data)
        {
            if (_count == 0)
            {
                _linkHead = new DoublyNode <T>(data, null, null);
                goto endAddCount;
            }
            else
            {
                var node    = GetNode(_count - 1);
                var newNode = new DoublyNode <T>(data, _linkHead, node);
                _linkHead.Prev = newNode;
                node.Next      = newNode;
                goto endAddCount;
            }

endAddCount:
            _count++;
        }
예제 #3
0
        public void Insert(int index, T data)
        {
            if (index == 0 && _count == 0)
            {
                AppendEnd(data);
                return;
            }
            if (index == 0)
            {
                var prevNode = GetNode(_count - 1);
                var nextNode = GetNode(index);
                var newNode  = new DoublyNode <T>(data, nextNode, prevNode);
                prevNode.Next = newNode;
                nextNode.Prev = newNode;
                goto endAddCount;
            }
            else
            {
                //末尾
                if (index == _count - 1)
                {
                    var prevNode = GetNode(index);
                    var nextNode = _linkHead;
                    var newNode  = new DoublyNode <T>(data, nextNode, prevNode);
                    prevNode.Next  = newNode;
                    _linkHead.Prev = newNode;
                    goto endAddCount;
                }
                else
                {
                    var prevNode = GetNode(index - 1);
                    var nextNode = GetNode(index);
                    var newNode  = new DoublyNode <T>(data, nextNode, prevNode);
                    prevNode.Next = newNode;
                    nextNode.Prev = newNode;
                    goto endAddCount;
                }
            }
endAddCount:
            _count++;
        }
예제 #4
0
 public DoublyNode(T data, DoublyNode <T> next, DoublyNode <T> prev)
 {
     Data = data;
     Next = next;
     Prev = prev;
 }