So far, we have seen a linked list using only one value, which is the node data. Now we need to pass another value that will be the priority. In order to achieve that, we need to change our ListNode implementation:
class ListNode {
public $data = NULL;
public $next = NULL;
public $priority = NULL;
public function __construct(string $data = NULL, int $priority =
NULL) {
$this->data = $data;
$this->priority = $priority;
}
}
Now we have both the data and the priority as part of the node. In order to allow this priority to be considered during the insert operation, we also need to change our insert() implementation inside the LinkedList class. Here is the modified implementation:
public function insert(string $data = NULL, int $priority = NULL) {
$newNode = new ListNode($data, $priority);
$this...