Пример #1
0
        public T this[int index]
        {
            get
            {
                return(GetCurrentNode(index).Value);
            }

            set
            {
                if ((index >= 0) && (index < Length))
                {
                    DLNode <T> current = _root;

                    for (int i = 1; i <= index; i++)
                    {
                        current = current.Next;
                    }

                    current.Value = value;
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
        }
Пример #2
0
        public DLinkedList(T[] values)
        {
            if (!(values is null))
            {
                Length = values.Length;

                if (values.Length != 0)
                {
                    _root = new DLNode <T>(values[0]);
                    _tail = _root;

                    for (int i = 1; i < values.Length; i++)
                    {
                        _tail.Next          = new DLNode <T>(values[i]);
                        _tail.Next.Previous = _tail;
                        _tail = _tail.Next;
                    }
                }
                else
                {
                    _root = null;
                    _tail = null;
                }
            }
Пример #3
0
 public DLNode(T value)
 {
     Value    = value;
     Next     = null;
     Previous = null;
 }
Пример #4
0
 public DLinkedList(T value)
 {
     Length = 1;
     _root  = new DLNode <T>(value);
     _tail  = _root;
 }
Пример #5
0
 public DLinkedList()
 {
     Length = 0;
     _root  = null;
     _tail  = null;
 }