예제 #1
0
        public void RemoveFirst()
        {
            if (First != null)
            {
                Count--;
                First.List = null;
            }

            First = First?.Next;

            if (First != null)
            {
                First.Previous.Next = null;
                First.Previous      = null;
            }
        }
예제 #2
0
        public void RemoveLast()
        {
            if (Last != null)
            {
                Count--;
                Last.List = null;
            }

            Last = Last?.Previous;

            if (Last != null)
            {
                Last.Next.Previous = null;
                Last.Next          = null;
            }
        }
예제 #3
0
        public void AddLast(MyLinkedListNode <T> Value)
        {
            if (Value.List == this)
            {
                throw new InvalidOperationException();
            }

            if (Last == null)
            {
                InicializeFirstElement(Value);
                return;
            }

            Count++;
            Value.List     = this;
            Last.Next      = Value;
            Value.Previous = Last;
            Last           = Value;
        }
예제 #4
0
        public void Remove(MyLinkedListNode <T> Insert)
        {
            if (Insert.List != this)
            {
                throw new ArgumentException();
            }

            Count--;
            Insert.List = null;
            if (Insert == Last)
            {
                Last = Insert.Previous;
            }

            if (Insert == First)
            {
                First = Insert.Next;
            }


            if (Insert.Next == null && Insert.Previous == null)
            {
                Clear();
            }

            else if (Insert.Next == null)
            {
                Insert.Previous.Next = null;
            }

            else if (Insert.Previous == null)
            {
                Insert.Next.Previous = null;
            }

            else
            {
                Insert.Next.Previous = Insert.Previous;
                Insert.Previous.Next = Insert.Next;
            }
        }
예제 #5
0
        public void AddBefore(MyLinkedListNode <T> Current, MyLinkedListNode <T> Insert)
        {
            var currPrevious = Current.Previous;

            if (Insert.List == this)
            {
                throw new InvalidOperationException();
            }

            if (currPrevious == null)
            {
                AddFirst(Insert);
                return;
            }

            Count++;
            Insert.List       = this;
            Current.Previous  = Insert;
            Insert.Next       = Current;
            Insert.Previous   = currPrevious;
            currPrevious.Next = Insert;
        }
예제 #6
0
 public void Reset()
 {
     Curr = StartPosition;
 }
예제 #7
0
        private void InicializeFirstElement(T Value)
        {
            MyLinkedListNode <T> Insert = new MyLinkedListNode <T>(Value);

            InicializeFirstElement(Insert);
        }
예제 #8
0
        public void AddBefore(MyLinkedListNode <T> Current, T Value)
        {
            var Insert = new MyLinkedListNode <T>(Value);

            AddBefore(Current, Insert);
        }
예제 #9
0
        public void AddLast(T Value)
        {
            var Insert = new MyLinkedListNode <T>(Value);

            AddLast(Insert);
        }