I have wrote most of my Enqueue function but need help on a small part of it.
struct Node
{Node* nextPtr; Node* previousPtr; Message data;}
class Priority
private: {Node* frontPtr; Node* rearPtr; int count;}
Here is my function:
And here is the specific part I am struggling on, just a few lines that need to be wrote:Code:void PriorityQ::Enqueue(Message msg) { if (IsFull()) throw FullPQ(); else { Node* temp1; temp1 = new Node; // creat new node temp1->data = msg; //data in node will be the message temp1->nextPtr = NULL; temp1->previousPtr = NULL; if ( (frontPtr == NULL) && (rearPtr == NULL) ) { temp1->nextPtr = frontPtr; //sets the node frontPtr = temp1; rearPtr = frontPtr; } else { int num = 0; Node* curPtr; Node* temp; curPtr = frontPtr; temp=curPtr; // Figure out the entry that should the value should be inserted at while ((curPtr != NULL) && (msg.GetPriority() <= curPtr->data.GetPriority())) { temp=curPtr; curPtr = curPtr->nextPtr; num++; } //correct if entry should be after the end of the list if(curPtr == NULL) { curPtr=temp; //new entry will be last entry rearPtr=temp1; } if(msg.GetPriority() > curPtr->data.GetPriority()) { //insert temp1 before the curPtr node temp1->previousPtr=curPtr->previousPtr; temp1->nextPtr=curPtr; curPtr->previousPtr=temp1; while(curPtr != NULL) { } //Not sure if above is correct but if need to insert entry before the node that //curPtr is pointing to and it is pointing to an entry(its not at the front), need //to make sure to point to previousPtr. But if curPtr does not point to a previous node, //then it becomes the new pointer(ie. change frontPtr to temp. //there are about 4 lines missing } else { // insert temp1 after the curPtr node temp1->nextPtr=curPtr->nextPtr; temp1->previousPtr=curPtr; //previous of new node will be current curPtr->nextPtr=temp1; //Above is correct, now: the node that the curPtr points to has a previousPtr //that is pointing to curPtr. Make sure, the node curPrt points to is not NULL. //may or may not be a node after curPtr //there are about 2 lines missing for this while(curPtr != NULL) //not sure here } } // Increment the counter count++; } }
Code:if(msg.GetPriority() > curPtr->data.GetPriority()) { //insert temp1 before the curPtr node temp1->previousPtr=curPtr->previousPtr; temp1->nextPtr=curPtr; curPtr->previousPtr=temp1; while(curPtr != NULL) { } //Not sure if above is correct but if need to insert entry before the node that //curPtr is pointing to and it is pointing to an entry(its not at the front), need //to make sure to point to previousPtr. But if curPtr does not point to a previous node, //then it becomes the new pointer(ie. change frontPtr to temp. //there are about 4 lines missing } else { // insert temp1 after the curPtr node temp1->nextPtr=curPtr->nextPtr; temp1->previousPtr=curPtr; //previous of new node will be current curPtr->nextPtr=temp1; //Above is correct, now: the node that the curPtr points to has a previousPtr //that is pointing to curPtr. Make sure, the node curPrt points to is not NULL. //may or may not be a node after curPtr //there are about 2 lines missing for this while(curPtr != NULL) //not sure here }



LinkBack URL
About LinkBacks



