示例#1
0
 /// <summary>
 ///     CreatSingleLink
 /// </summary>
 private void CreatSingleLink()
 {
     this.head = new LinkListNode(this, -1);
 }
示例#2
0
        /// <summary>
        ///     remove the next node after this
        /// </summary>
        /// <param name="node">node</param>
        private void RemoveNextNode(LinkListNode node)
        {
            if (node.Next == node.List.head.Next)
            {
                node.List.head._next = node.Next.Next;
            }

            node._next = node.Next.Next;
            if ((node.ListType & LinkListType.DoubleLink) == LinkListType.DoubleLink)
            {
                node.Next._previous = node;
            }

            this.Count--;
        }
示例#3
0
 /// <summary>
 ///     CreatCirculateLink
 /// </summary>
 /// <param name="head">turn head item type</param>
 private void CreatCirculateLink(LinkListNode head)
 {
     head._listType = this._listType;
     head._next = head;
     head._previous = head;
 }
示例#4
0
        /// <summary>
        ///     add a new item after index k
        /// </summary>
        /// <param name="send">new item</param>
        /// <param name="index">index k</param>
        private void AddNewItem(LinkListNode send, int index)
        {
            if (index > this.Count)
            {
                index = index % (this.Count + 1) + 1;
            }

            var item = new LinkListNode(this, send.Data);
            LinkListNode node = this.head;
            for (int i = 0; i < index; i++)
            {
                if (node == null)
                {
                    return;
                }

                node = node.Next;
            }

            LinkListNode originalNext = node.Next;
            node._next = item;
            item._next = originalNext;

            if ((this._listType & LinkListType.DoubleLink) == LinkListType.DoubleLink)
            {
                item._previous = node;
                if (originalNext != null)
                {
                    originalNext._previous = item;
                }
            }

            this.Count++;
        }
示例#5
0
 /// <summary>
 ///     remove the node after this
 /// </summary>
 /// <param name="node">this node</param>
 public void Delete(LinkListNode node)
 {
     this.RemoveNextNode(node);
 }
示例#6
0
 /// <summary>
 ///     add a new item after kth item
 /// </summary>
 /// <param name="item">new item</param>
 /// <param name="index">index of k</param>
 public void Add(LinkListNode item, int index)
 {
     this.AddNewItem(item, index);
 }
示例#7
0
 /// <summary>
 ///     add a new item
 /// </summary>
 /// <param name="item">new item</param>
 public void Add(LinkListNode item)
 {
     this.AddNewItem(item, this.Count);
 }