Beispiel #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();
                }
            }
        }
Beispiel #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;
                }
            }
Beispiel #3
0
 public DLNode(T value)
 {
     Value    = value;
     Next     = null;
     Previous = null;
 }
Beispiel #4
0
 public DLinkedList(T value)
 {
     Length = 1;
     _root  = new DLNode <T>(value);
     _tail  = _root;
 }
Beispiel #5
0
 public DLinkedList()
 {
     Length = 0;
     _root  = null;
     _tail  = null;
 }