コード例 #1
0
ファイル: LListR.cs プロジェクト: RomanGolovko/Valtech_
 public void AddFirst(int value)
 {
     _head = new NodeR(value) { Next = _head, Previous = _tail };
     if (Size() == 1)
     {
         _tail = _head;
     }
     _head.Previous = _tail;
     _tail.Next = _head;
 }
コード例 #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;
 }
コード例 #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);
        }
コード例 #4
0
ファイル: LListR.cs プロジェクト: RomanGolovko/Valtech_
        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;
            }
        }
コード例 #5
0
ファイル: LListR.cs プロジェクト: RomanGolovko/Valtech_
        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;
        }
コード例 #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);
        }
コード例 #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;
            }
        }
コード例 #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);
        }
コード例 #9
0
ファイル: LListR.cs プロジェクト: RomanGolovko/Valtech_
        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;
        }
コード例 #10
0
ファイル: LListR.cs プロジェクト: RomanGolovko/Valtech_
 public void Clear()
 {
     _head = null;
     _tail = null;
 }
コード例 #11
0
ファイル: LListR.cs プロジェクト: RomanGolovko/Valtech_
        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;
        }
コード例 #12
0
 public void Clear()
 {
     _head = null;
     _tail = null;
 }