For my Computer Science class I am implementing a templated
Priority Queue class and I am struggling to implement the enqueue
function. I know the error is in the if(value < back)
block of the function.
Here is the Function:
template<class T>
bool PriorityQueue<T>::enqueue(T& value){
if(!isEmpty()){
if(value < back()){
Node<T>* curr = f_ptr;
Node<T>* prev = NULL;
while(value > curr->data() && curr != NULL){
prev = curr;
curr = curr->m_next;
}
if(curr != NULL && value == curr->data()){
prev = curr;
curr = curr->m_next;
}
Node<T>* tmp = new Node<T>(value,curr);
prev->m_next = tmp;
return true;
}else{
b_ptr->m_next = new Node<T>(value);
b_ptr = b_ptr->m_next;
}
}else{
f_ptr = new Node<T>(value);
b_ptr = f_ptr;
return true;
}
}
The Helper functions are all functioning properly. Please explain what part of my logic is incorrect.