Esempio n. 1
0
 public void AddFirst(int value)
 {
     _head = new NodeR(value) { Next = _head, Previous = _tail };
     if (Size() == 1)
     {
         _tail = _head;
     }
     _head.Previous = _tail;
     _tail.Next = _head;
 }
Esempio n. 2
0
 public void AddFirst(int value)
 {
     _head = new NodeR(value)
     {
         Next = _head, Previous = _tail
     };
     if (Size() == 1)
     {
         _tail = _head;
     }
     _head.Previous = _tail;
     _tail.Next     = _head;
 }
Esempio n. 3
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
            {
                NodeR previous = null;
                var   current  = _head;
                var   index    = 0;

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

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

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

                        value = current.Value;
                    }
                    previous = current;
                    current  = current.Next;
                    index++;
                }
            }
            return(value);
        }
Esempio n. 4
0
        public void AddLast(int value)
        {
            var node = new NodeR(value) { Next = _head };

            if (Size() == 0)
            {
                _head = node;
                _tail = _head;
                _tail.Next = _head;
                _head.Previous = _tail;
            }
            else
            {
                _tail.Next = node;
                node.Previous = _tail;
                node.Next = _head;
                _head.Previous = node;
            }
        }
Esempio n. 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 = _tail;
                _tail.Next = _head;
            }
            return value;
        }
Esempio n. 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 = _head;
                _tail          = _tail.Previous;
                _head.Previous = _tail;
            }
            return(value);
        }
Esempio n. 7
0
        public void AddLast(int value)
        {
            var node = new NodeR(value)
            {
                Next = _head
            };

            if (Size() == 0)
            {
                _head          = node;
                _tail          = _head;
                _tail.Next     = _head;
                _head.Previous = _tail;
            }
            else
            {
                _tail.Next     = node;
                node.Previous  = _tail;
                node.Next      = _head;
                _head.Previous = node;
            }
        }
Esempio n. 8
0
        public int Size()
        {
            if (_tail != null)
            {
                _tail.Next = null;
            }

            var index   = 0;
            var current = _head;

            while (current != null)
            {
                index++;
                _tail   = current;
                current = current.Next;
            }

            if (_tail != null || _head != null)
            {
                _tail.Next = _head;
            }
            return(index);
        }
Esempio n. 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
            {
                NodeR previous = null;
                var current = _head;
                var index = 0;

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

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

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

                        value = current.Value;
                    }
                    previous = current;
                    current = current.Next;
                    index++;
                }
            }
            return value;
        }
Esempio n. 10
0
 public void Clear()
 {
     _head = null;
     _tail = null;
 }
Esempio n. 11
0
        public int Size()
        {
            if (_tail != null)
            {
                _tail.Next = null;
            }

            var index = 0;
            var current = _head;
            while (current != null)
            {
                index++;
                _tail = current;
                current = current.Next;
            }

            if (_tail != null || _head != null)
            {
                _tail.Next = _head;
            }
            return index;
        }
Esempio n. 12
0
 public void Clear()
 {
     _head = null;
     _tail = null;
 }