public void RemoveBack() { if (_count > 1) { _tail = _tail.Prev; _tail.Next = null; _count--; } else { _head = _tail = null; _count = 0; } }
public void RemoveFront() { if (_count > 1) { _head = _head.Next; _head.Prev = null; _count--; } else { _head = _tail = null; _count = 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++; } }
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++; } }
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); } }
public void Clear() { _head.Prev = _head.Next = _tail.Prev = _tail.Next = _tail = _head = null; _count = 0; }
public DLNode(T value, DLNode <T> prev = null, DLNode <T> next = null) { _value = value; _ptr_prev = prev; _ptr_next = next; }