これを呼び出すhead->value
と、リンクされたリストに追加された最後の値が返されます。head
空の場合にのみ設定されるため、最初のアイテムを返す必要はありませんか? 正しい?コードに他のバグがあるのではないかと考えています。
void LinkedListPQueue::enqueue(const string& elem) {
cell *newCell = new cell;
newCell->value = elem;
newCell->next = NULL;
if(this->isEmpty()) {
this->head = this->tail = newCell;
} else {
// find smallest and put it there
this->tail->next = newCell;
this->tail = newCell;
}
}
ヘッダーで宣言
struct cell {
std::string value;
cell *next;
};
cell *head, *tail;