public void insertNode(SourceNode insertNode) { SourceNode pointer = head; while (pointer.getNext() != null) { if (comesAfterNode(insertNode, pointer.getNext())) { SourceNode temp = pointer.getNext(); pointer.setNext(insertNode); pointer.getNext().setNext(temp); return; } pointer = pointer.getNext(); } pointer.setNext(insertNode); }
public void setNext(SourceNode next) { this.next = next; }
//I created this function so that when we add more criteria to determining what sources come in what order, //such as commission rates, we can easily add them here. public bool comesAfterNode(SourceNode insert, SourceNode current) { if (current == head) { return false; } if (insert.getPrice() <= current.getPrice()) { return true; } return false; }