コード例 #1
0
 public void AddFirst(CustomLinkedListNode <T> node)
 {
     Head.Previous = node;
     node.Next     = Head;
     Head          = node;
     Count++;
 }
コード例 #2
0
 public void AddLast(CustomLinkedListNode <T> node)
 {
     Tail.Next     = node;
     node.Previous = Tail;
     Tail          = node;
     Count++;
 }
コード例 #3
0
        public void Insert(int index, T value)
        {
            var newNode = new CustomLinkedListNode <T>(value);
            var current = Head;
            int counter = 0;

            if (!ReferenceEquals(Head, current))
            {
                while (counter < index)
                {
                    current = current.Next;
                    counter++;
                }

                current.Previous.Next = newNode;
                newNode.Next          = current;
                newNode.Previous      = current.Previous;
                current.Previous      = newNode;
                Count++;
            }
            else
            {
                current.Previous = newNode;
                newNode.Next     = current;
                Head             = newNode;
                Count++;
            }
        }
コード例 #4
0
        private void Initialize(T value)
        {
            var item = new CustomLinkedListNode <T>(value);

            Head  = item;
            Tail  = item;
            Count = 1;
        }
コード例 #5
0
 public void AddBefore(CustomLinkedListNode <T> node, CustomLinkedListNode <T> newNode)
 {
     node.Previous.Next = newNode;
     newNode.Previous   = node.Previous;
     newNode.Next       = node;
     node.Previous      = newNode;
     Count++;
 }
コード例 #6
0
 public void AddAfter(CustomLinkedListNode <T> node, CustomLinkedListNode <T> newNode)
 {
     node.Next.Previous = newNode;
     newNode.Next       = node.Next;
     newNode.Previous   = node;
     node.Next          = newNode;
     Count++;
 }
コード例 #7
0
        public CustomLinkedListNode <T> AddAfter(CustomLinkedListNode <T> node, T value)
        {
            var newNode = new CustomLinkedListNode <T>(value);

            node.Next.Previous = newNode;
            newNode.Next       = node.Next;
            newNode.Previous   = node;
            node.Next          = newNode;
            Count++;
            return(newNode);
        }
コード例 #8
0
        public CustomLinkedListNode <T> AddBefore(CustomLinkedListNode <T> node, T value)
        {
            var newNode = new CustomLinkedListNode <T>(value)
            {
                Previous = node.Previous
            };

            node.Previous.Next = newNode;
            newNode.Next       = node;
            node.Previous      = newNode;
            Count++;

            return(newNode);
        }
コード例 #9
0
 public void Add(T data)
 {
     if (Tail != null)
     {
         var item = new CustomLinkedListNode <T>(data);
         Tail.Next     = item;
         item.Previous = Tail;
         Tail          = item;
         Count++;
     }
     else
     {
         Initialize(data);
     }
 }
コード例 #10
0
        public void Remove(CustomLinkedListNode <T> node)
        {
            if (ReferenceEquals(node, Head))
            {
                RemoveFirst();
                return;
            }

            if (ReferenceEquals(node, Tail))
            {
                RemoveLast();
                return;
            }

            node.Previous.Next = node.Next;
            node.Next.Previous = node.Previous;
            node.Next          = null;
            node.Previous      = null;
            Count--;
        }