public void Exit(LinkedAgentPointer pointer) { var isFirst = pointer == First; var isLast = pointer == Last; var next = pointer.Next; var previous = pointer.Previous; if (previous != null) { previous.Next = next; } if (next != null) { next.Previous = previous; } pointer.Next = pointer.Previous = null; pointer.Chain = null; if (isFirst) { First = previous; } if (isLast) { Last = next; } }
public LinkedAgentPointer Enter(IAgent agent) { if (First == null && Last == null) { return(Last = First = new LinkedAgentPointer(agent, this)); } var current = Last; while (current != null && current.Agent.Progress < agent.Progress) { current = current.Next; } LinkedAgentPointer previous, next; if (current == null) // we went to far { previous = First; next = null; } else { previous = current.Previous; next = current; } current = new LinkedAgentPointer(agent, this); current.Next = next; if (next != null) { next.Previous = current; } current.Previous = previous; if (previous != null) { previous.Next = current; } if (current.Next == null) { First = current; } if (current.Previous == null) { Last = current; } return(current); }