public override void Add(T item) { Node <T> node = new Node <T>(item); if (_size == 0) { _first = node; } else { node.SetNext(_first); _first.SetPrevious(node); _first = node; } _size++; OnAddElement(new DataStructEventArgs <T>(item)); }
public T GetFirst() { if (_size == 0) { throw new DataStructureIsEmptyOnReadExeption("Linked List"); } Node <T> result = _first; _first = _first.GetNext(); if (_size == 1) { Clear(); } else { _first.SetPrevious(null); _size--; } OnRemoveElement(new DataStructEventArgs <T>(result.GetItem())); return(result.GetItem()); }
public RingBufferLinkedList(int length) { if (length < 1) { throw new ArgumentException(); } _first = new Node <T>(); Node <T> currentNode = _first; for (int i = 0; i < length - 1; i++) { currentNode.SetNext(new Node <T>()); currentNode.GetNext().SetPrevious(currentNode); currentNode = currentNode.GetNext(); } currentNode.SetNext(_first); _first.SetPrevious(currentNode); _size = length; _end = _first.GetPrevious(); }