Пример #1
0
 public void RemoveBack()
 {
     if (_count > 1)
     {
         _tail      = _tail.Prev;
         _tail.Next = null;
         _count--;
     }
     else
     {
         _head  = _tail = null;
         _count = 0;
     }
 }
Пример #2
0
 public void RemoveFront()
 {
     if (_count > 1)
     {
         _head      = _head.Next;
         _head.Prev = null;
         _count--;
     }
     else
     {
         _head  = _tail = null;
         _count = 0;
     }
 }
Пример #3
0
 public void Add(T item)
 {
     if (_count == 0)
     {
         _head = _tail = new DLNode <T>(item);
         _count++;
     }
     else
     {
         DLNode <T> newnode = new DLNode <T>(item, _tail);
         _tail.Next = newnode;
         _tail      = newnode;
         _count++;
     }
 }
Пример #4
0
 public void AddFront(T item)
 {
     if (_count == 0)
     {
         _head = _tail = new DLNode <T>(item);
         _count++;
     }
     else
     {
         var newnode = new DLNode <T>(item, null, _head);
         _head.Prev = newnode;
         _head      = newnode;
         _count++;
     }
 }
Пример #5
0
 public void Insert(int index, T item)
 {
     if (index == 0)
     {
         AddFront(item);
     }
     else if (index > 0 && index < _count)
     {
         var        current  = GetNode(index);
         DLNode <T> new_node = new DLNode <T>(item, current.Prev, current);
         current.Prev.Next = new_node;
         current.Prev      = new_node;
         _count++;
     }
     else if (index == _count)
     {
         Add(item);
     }
 }
Пример #6
0
 public void Clear()
 {
     _head.Prev = _head.Next = _tail.Prev = _tail.Next = _tail = _head = null;
     _count     = 0;
 }
Пример #7
0
 public DLNode(T value, DLNode <T> prev = null, DLNode <T> next = null)
 {
     _value    = value;
     _ptr_prev = prev;
     _ptr_next = next;
 }