Exemple #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;
            }
        }
Exemple #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;
            }
        }
Exemple #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;
        }
Exemple #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;
            }
        }
Exemple #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;
        }
Exemple #6
0
 public void Reset()
 {
     Curr = StartPosition;
 }
Exemple #7
0
        private void InicializeFirstElement(T Value)
        {
            MyLinkedListNode <T> Insert = new MyLinkedListNode <T>(Value);

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

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

            AddLast(Insert);
        }