私は、Cスタイルctor
とdtor
のリンクリストを持っています。C++キューの途中からノードを削除
このif文が真であることをテストしないと決めたとき、私はあまりにも不満を持ちました。 に無限ループを入れました。私はそれが本当にテストされない理由を理解していない。
LinkedList
からノード(クラスオブジェクトのアドレス)を削除しようとしています。
誰かが私を助けてくれるのでしょうか?
Node *Current = first_; // I want this to be my only Node Ptr Varaible Declaration.
if (NULL == first_)
std::cout << "Cannot delete from an empty list: \n";
while (Current != NULL)
{
if (first_->data_ == node->data_)
{
//check to see if we are deleteing the head.
first_ = first_->next_;
--listLen_;
delete Current;
std::cout << "Head Deleted!\n";
}
if (Current->data_ == node->data_) // FOR SOME REASON this is never true?
{
--listLen_;
node->data_ = NULL;
Current = Current->next_;
node->data_ = Current;
}
else // we must not of found it. // else should match previous i
{
Current->prev_ = Current;// since we are not deleting the first node we are OK here.
Current = first_->next_;
if (Current->next_ == NULL) // see if we are at the end of the list.
{
first_ = NULL;
last_ = Current->prev_;
}
}
}
return;
コードの書式が正しく設定されていません。 –
コードの書式設定を修正しました。 –
あなたの特定の質問は何ですか? –