1

これを呼び出す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;
4

1 に答える 1

6

私のbeisEmptyは正しく実装されていないため、新しいノードを追加するたびに、そのノードに頭を再割り当てします

于 2013-01-12T14:23:35.097 に答える