public void AddFirst(int value) { _head = new NodeR(value) { Next = _head, Previous = _tail }; if (Size() == 1) { _tail = _head; } _head.Previous = _tail; _tail.Next = _head; }
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); }
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; } }
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; }
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); }
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); }
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; }
public void Clear() { _head = null; _tail = null; }
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; }