Ejemplo n.º 1
0
 public MListIterator(MList <T> _list, MListNode <T> _previous)
 {
     list     = _list;
     previous = _previous;
     current  = null;
     next     = _previous.Next;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
    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++;
    }
Ejemplo n.º 6
0
 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
 }
Ejemplo n.º 7
0
        tail;         // last node, containing real data

    // TODO: iterator for internal use to prevent 'new' calls

    public MList()
    {
        root = new MListNode <T>(); tail = null;
    }