对于我的计算机科学课,我正在实现一个templated
优先队列类,并且我正在努力实现该enqueue
功能。我知道错误在if(value < back)
函数块中。这是功能:
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;
}
}
助手功能都正常运行。请解释我的逻辑的哪一部分不正确。