I'm trying to insert a request and sort it via priority, so highest(1) is first in the list.
public Node addByPriority(Object request, int priority) {
size++;
//creates a new node with a priority, owner and creator and sets its next node to the root
Node newNode = new Node(request, priority);
//node to store prev
Node prevNode = null;
//node to store current
Node currNode = first;
//cycle thru the nodes til either the priority is higher or current is null
while (currNode != null && priority >= currNode.getPriority()) {
prevNode = currNode;
currNode = currNode.getNext();
}
if (prevNode == null) {
newNode.setNext(first);
first = newNode;
}
else {
prevNode.setNext(newNode);
newNode.setNext(currNode);
}
// what would be the return statement??
}
It says I need a return statement but not sure what has to be put, or if there's another way.