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++;
}
}