Ejemplo n.º 1
0
        public void Remove(CircularNode node)
        {
            if (node.List != this)
            {
                throw new InvalidOperationException("Node is not assigned to this list!");
            }

            if (_size <= 0)
            {
                throw new InvalidOperationException("List is empty can't remove!");
            }

            node.List = null;

            if (_size == 1)
            {
                _first = null;
            }

            else
            {
                if (_first == node)
                {
                    _first = (T)_first.Next;
                }

                node.Previous.Next = node.Next;
                node.Next.Previous = node.Previous;
            }

            node.Previous = null;
            node.Next     = null;

            _size--;
        }
Ejemplo n.º 2
0
        public void AddPrevious(CircularNode node, CircularNode newNode)
        {
            if (newNode.List != null)
            {
                throw new InvalidOperationException("Node is already assigned to different list!");
            }

            newNode.List = this;

            newNode.Previous = node.Previous;
            newNode.Next     = node;

            node.Previous.Next = newNode;
            node.Previous      = newNode;

            _size++;
        }
Ejemplo n.º 3
0
        public void AddLast(CircularNode node)
        {
            if (node.List != null)
            {
                throw new InvalidOperationException("Node is already assigned to different list!");
            }

            if (_first == null)
            {
                _first = node as T;

                node.List     = this;
                node.Next     = node;
                node.Previous = node;

                _size++;
            }
            else
            {
                AddPrevious(_first, node);
            }
        }