public Output addOrder(Order ord) { LLNode order = new LLNode(ord); _orderIDLkp.Add(ord.OrderID, ord); OrdersLinkedList relevantList = ord.IsBuy ? _buyLinkedList : _sellLinkedList; relevantList.insert(order); return isChanged(ord.IsBuy, ord); }
public void insert(LLNode newNode) { if (_head == null || _head.Value.CompareTo(newNode.Value) > 0) { newNode.Next = _head; _head = newNode; } else { LLNode current = _head; while (current.Next != null && current.Next.Value.CompareTo(newNode.Value) < 0) { current = current.Next; } newNode.Next = current.Next; current.Next = newNode; } }
public void remove(Order orderToRemove) { if (_head == null) throw new InvalidOperationException("Cannot remove orders when there are no orders"); if (_head.Value.Equals(orderToRemove)) { LLNode current = _head; _head = _head.Next; current.Value = null; current.Next = null; //current = null; } else { LLNode current = _head; while (current.Next != null && current.Next.Value.Equals(orderToRemove) == false) { current = current.Next; } if (current.Next == null) throw new Exception("Order to remove not found in OrderBook"); //set previous nodes next to deleted nodes next LLNode nodeToDelete = current.Next; current.Next = nodeToDelete.Next;// current.Next.Next; nodeToDelete.Next = null; nodeToDelete.Value = null; nodeToDelete = null; } }