<分区>
当我调用 extractMin()
时这段代码崩溃了不止一次。我认为这应该是显而易见的
你们中的一些人问题出在函数上,因为我是指针的新手,可能是一个明显的错误。所以你知道它是一个链表就足够了,除了函数应该使用 <
来检索字典序最小值之外,无需详细说明。运算符,然后从链表中删除该值。
string LinkedListPQueue::extractMin() {
if (this->isEmpty()) throw ErrorException("Empty queue.");
string front = LEX_HIGH;
cell *old;
for (int i = 0; i < this->size(); i++) {
if (this->head->value < front) {
front = this->head->value;
old = this->head;
}
old = this->head;
this->head = this->head->next;
}
logSize--;
delete old;
return front;
}
void LinkedListPQueue::enqueue(const string& elem) {
cell *newCell = new cell;
newCell->value = elem;
newCell->next = NULL;
if(this->isEmpty()) {
this->head = this->tail = newCell;
logSize++;
} else {
recurSort(newCell);
this->tail->next = newCell;
this->tail = newCell;
logSize++;
}
}