You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{ deletePriorityPCBQueue(); //first deletes any queue that might already exist
PriorityPCBNode* temp = rightSide.head; //creates temp Node ptr to move through rightSide queue
head = newPriorityPCBNode(temp->getPriority(), temp->getPCB_ID(), nullptr); //head now points at new Node object
tail = head; //tail now point at same Node object as head
temp = temp->getNext(); //temp ptr points to second node in rightSide or nullptr if there is now second node
while(temp != nullptr) //if temp does not point to nullptr there are more nodes in rightSide
{ tail->setNextNode(newPriorityPCBNode(temp->getPriority(), temp->getPCB_ID(), nullptr)); //sets next of the node tail points to
tail = tail->getNext(); //tail now points at the new node object just created by setNextNode()
temp = temp->getNext(); //temp now point at next node in rightSide or nullptr if end of aQueue
}
return *this;
}
voidPriorityPCBQueue::deletePriorityPCBQueue() //delete function
{ if(head != nullptr) //checks to see if queue is already empty
{ PriorityPCBNode* temp = head; // if queue is not empty creat temp Node pointer to move through queue
while(head != nullptr) // while head ptr doesn't point to a nullptr we have not yet reached the end
{ head = head->getNext(); // head now points to the next node in the queue
delete temp; // the node head used to point to is now deleted
temp = head; // temp again point to the same node as head
}
tail = nullptr; //set tail to nullptr to avoid dangling pointer
}
}
PriorityPCBQueue::~PriorityPCBQueue()
{
deletePriorityPCBQueue();
}
voidPriorityPCBQueue::add(int thePriority, int thePCB_ID) //mutator function to add node to queue using priority variable to determine
{ //order in queue. Higher number means higher priority and thus closer placement
//to head of the queue
if(isEmpty()==true) //if queue is empty
{ head = newPriorityPCBNode(thePriority, thePCB_ID, nullptr); //add item to head of queue
tail = head; //tail and head both point to the one object in the queue
}
else//if queue is not empty
{ PriorityPCBNode* temp = head;
if(thePriority > head->getPriority())
{ head = newPriorityPCBNode(thePriority, thePCB_ID, head);
}
else
{
while(temp->getNext() != nullptr && thePriority <= temp->getNext()->getPriority()) //checks to see if Node has higher priority than the node pointed at by tail
{ temp = temp->getNext();
}
if(temp->getNext() == nullptr)
{ tail->setNextNode(newPriorityPCBNode(thePriority, thePCB_ID, nullptr)); //create new node and add item to end of queue
tail = tail->getNext(); //tail now point at new node at end of queue