Given the following structure, private members, and message functions:
struct Node // Linked priority queue node structure
{
Message data; // Field for storing data in the priority queue node
Node* nextPtr; // Points to next priority queue node
Node* previousPtr; // Points to previous priority queue node
};
private:
Node* frontPtr; // Points to front node of priority queue
Node* rearPtr; // Points to rear node of priority queue
int count; // Number of values stored in priority queue
Message.cpp file functions:
//Initializes message to empty string with UNKNOWN (0) priority
Message::Message()
{
message = "";
priority = UNKNOWN;
}
//Sets priority equal to p
void Message::SetPriority(Priorities p)
{
priority = p;
}
//Sets message equal to msg
void Message::SetMessage(string msg)
{
message = msg;
}
//Returns priority value without modification
Message::GetPriority() const
{
return priority;
}
//Returns message contents without modification
string Message::GetMessage() const
{
return message;
}
The biggest challenge of this project is the enqueue function in priorityq.cpp
so far all I have is this:
//Adds value to priority queue in correct position and increments count
//Duplicates are allowed
//Highest priority message must always be at the front of the queue
//Lowest priority messages must always be at the rear of the queue
//Add AFTER messages of similar priority
//If queue is already full, throws FullPQ exception
void PriorityQ::Enqueue(Message msg)
{
if (IsFull())
{
throw FullPQ();
}
else
{
int i=0;
Node* temp;
temp = new Node;
temp->data = msg;
if(IsEmpty())
{
temp->nextPtr = frontPtr;
temp->previousPtr = rearPtr;
}
else
{
if(Message::GetPriority() == HIGH)
{
while(i<=count&&temp->data.GetPriority() == HIGH)
{
}
}
}
count++;
}
}
This function is supposed to determine where to put the next piece of data (a message) and put it there, while keeping count. I really just have no idea what to do. This is due Friday at 10pm. Any help would be GREATLY appreciated!