コード例 #1
0
        /// <summary>
        /// Adds an item before the given item.
        /// </summary>
        /// <param name="pre"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool AddBefore(T pre, T value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null.");
            }

            IterableLinkedListNodeLink <T> node = this.FindNode(pre);

            if (node == null)
            {
                return(false);
            }

            IterableLinkedListNode <T> iterableLinkedListNode = new IterableLinkedListNode <T>(value, node.Child);

            if (node.Parent == null)
            {
                this.root = iterableLinkedListNode;
            }
            else
            {
                node.Parent.Next = iterableLinkedListNode;
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Adds an item after the given item.
        /// </summary>
        /// <param name="pre"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool AddAfter(T pre, T value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null.");
            }

            IterableLinkedListNodeLink <T> node = this.FindNode(pre);

            if (node == null)
            {
                return(false);
            }

            IterableLinkedListNode <T> iterableLinkedListNode = new IterableLinkedListNode <T>(value, node.Child.Next);

            node.Child.Next = iterableLinkedListNode;

            if (node.Child == this.tail)
            {
                this.tail = iterableLinkedListNode;
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Adds an item as the first element in this list.
        /// </summary>
        /// <param name="value"></param>
        public void AddFirst(T value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null.");
            }

            this.root = new IterableLinkedListNode <T>(value, this.root);

            if (this.tail == null)
            {
                this.tail = this.root;
            }
        }
コード例 #4
0
        /// <summary>
        /// Finds a node with the given value and returns the link between that node and its parent.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private IterableLinkedListNodeLink <T> FindNode(T value)
        {
            IterableLinkedListNode <T> parent = null;

            for (IterableLinkedListNode <T> child = this.root; child != null; child = child.Next)
            {
                if (child.Value.Equals((object)value))
                {
                    return(new IterableLinkedListNodeLink <T>(parent, child));
                }

                parent = child;
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Removes the first item in this list.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool RemoveFirst(out T value)
        {
            if (root == null)
            {
                value = default(T);
                return(false);
            }

            IterableLinkedListNode <T> oldRoot = root;

            value = oldRoot.Value;
            root  = oldRoot.Next;
            if (oldRoot == tail)
            {
                tail = root;
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Adds an item as the last element in this list.
        /// </summary>
        /// <param name="value"></param>
        public void AddLast(T value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null.");
            }

            IterableLinkedListNode <T> iterableLinkedListNode = new IterableLinkedListNode <T>(value, null);

            if (this.root == null)
            {
                this.root = iterableLinkedListNode;
                this.tail = iterableLinkedListNode;
            }
            else
            {
                this.tail.Next = iterableLinkedListNode;
                this.tail      = iterableLinkedListNode;
            }
        }
コード例 #7
0
        /// <summary>
        /// Removes an item with the given value.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Remove(T value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null.");
            }

            IterableLinkedListNodeLink <T> node = this.FindNode(value);

            if (node == null)
            {
                return(false);
            }

            if (root == node.Child)
            {
                this.root = node.Child.Next;

                if (this.root == null)
                {
                    this.tail = null;
                }
            }

            if (tail == node.Child)
            {
                this.tail = node.Parent;
            }

            if (node.Parent != null)
            {
                node.Parent.Next = node.Child.Next;
            }

            return(true);
        }
コード例 #8
0
 public void Dispose()
 {
     this.currentNode = null;
     this.sourceList  = null;
 }
コード例 #9
0
 public void Reset()
 {
     this.currentNode = this.sourceList.root;
 }
コード例 #10
0
        public bool MoveNext()
        {
            this.currentNode = this.currentNode != null ? this.currentNode.Next : this.sourceList.root;

            return(this.currentNode != null);
        }
コード例 #11
0
 public IterableLinkedListNodeLink(IterableLinkedListNode <T> parent, IterableLinkedListNode <T> child)
 {
     this.Parent = parent;
     this.Child  = child;
 }
コード例 #12
0
 public IterableLinkedListNode(T value, IterableLinkedListNode <T> next)
 {
     this.Value = value;
     this.Next  = next;
 }