public MListIterator(MList <T> _list, MListNode <T> _previous) { list = _list; previous = _previous; current = null; next = _previous.Next; }
public void _Skip() // internal operation to do on Remove { if (next == null) { previous.Next = null; // end of list next = current = previous = null; return; } previous.Next = next; current = null; }
/// <summary>Step to next node. Return true if there was next.</summary> public bool Next() { if (next == null) { return(false); } if (current != null) { previous = current; // current is null at the beginning and after Remove } current = next; next = current.Next; return(true); }
public MListNode <T> InsertAfter(MListNode <T> position, T t) { // add a node after 'position', which can't be null // special cases: first, only one, last UT.assert(position != null); MListNode <T> node = new MListNode <T> { value = t, Next = position.Next }; position.Next = node; if (tail == position) { tail = node; } size++; return(node); }
public void AddLast(T t) { MListNode <T> node = new MListNode <T> { value = t }; if (size == 0) { root.Next = node; } else { tail.Next = node; } tail = node; size++; }
public void InsertBefore(T t) { UT.assert(current != null); // can't be beginning or end of list, or just deleted previous = list.InsertAfter(previous, t); // add new node and update iterator's previous }
tail; // last node, containing real data // TODO: iterator for internal use to prevent 'new' calls public MList() { root = new MListNode <T>(); tail = null; }