Beispiel #1
0
 public void AddFirst(int value)
 {
     _head = new Node2(value) { Next = _head, Previous = null};
     if (Size() == 1)
     {
         _tail = _head;
     }
 }
Beispiel #2
0
        public void AddLast(int value)
        {
            var node = new Node2(value);

            if (Size() == 0)
            {
                _head = node;
            }
            else
            {
                _tail.Next    = node;
                node.Previous = _tail;
            }

            _tail = node;
        }
Beispiel #3
0
        public void AddLast(int value)
        {
            var node = new Node2(value);

            if (Size() == 0)
            {
                _head = node;
            }
            else
            {
                _tail.Next = node;
                node.Previous = _tail;
            }

            _tail = node;
        }
Beispiel #4
0
        public int DelLast()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _tail.Value;
            if (Size() == 1)
            {
                _head = null;
                _tail = null;
            }
            else
            {
                _tail.Previous.Next = null;
                _tail = _tail.Previous;
            }

            return value;
        }
Beispiel #5
0
        public int DelFirst()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _head.Value;
            _head = _head.Next;

            if (Size() == 0)
            {
                _tail = null;
            }
            else
            {
                _head.Previous = null;
            }

            return value;
        }
Beispiel #6
0
        public int DelLast()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _tail.Value;

            if (Size() == 1)
            {
                _head = null;
                _tail = null;
            }
            else
            {
                _tail.Previous.Next = null;
                _tail = _tail.Previous;
            }

            return(value);
        }
Beispiel #7
0
        public int DelFirst()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _head.Value;

            _head = _head.Next;

            if (Size() == 0)
            {
                _tail = null;
            }
            else
            {
                _head.Previous = null;
            }

            return(value);
        }
Beispiel #8
0
 public void Clear()
 {
     _head = null;
     _tail = null;
 }
Beispiel #9
0
        public int DelPosition(int position)
        {
            if (position <= 0 || position > Size() || Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = 0;
            if (Size() == 1)
            {
                value = _head.Value;
            }
            else
            {
                Node2 previous = null;
                var current = _head;
                var index = 0;

                while (current != null)
                {
                    if (index == position)
                    {
                        if (previous != null)
                        {
                            previous.Next = current.Next;

                            if (current.Next == null)
                            {
                                _tail = previous;
                            }
                        }
                        else
                        {
                            _head = _head.Next;

                            if (_head == null)
                            {
                                _tail = null;
                            }
                        }

                        value = current.Value;
                    }
                    previous = current;
                    current = current.Next;
                    index++;
                }
            }
            return value;
        }
Beispiel #10
0
 public void Clear()
 {
     _head = null;
     _tail = null;
 }