0
嘿傢伙,抱歉,但我是新來的雙鏈表,並想知道如果有人能告訴我爲什麼我的程序崩潰時,我使用add_end()?在C++中的鏈接列表
#include <iostream>
using namespace std;
node *start_ptr = NULL;
node *current;
int option = 0;
void add_end()
{
node *temp, *temp2;
temp = new node;
cout << "Enter name: ";
cin >> temp->name;
cout << "Enter profession: ";
cin >> temp->profession;
cout << "Enter age: ";
cin >> temp->age;
temp->nxt = NULL;
if (start_ptr = NULL)
{
start_ptr = temp;
current = start_ptr;
}
else
{
temp2 = start_ptr;
while (temp2->nxt != NULL)
{
temp2 = temp2->nxt;
}
temp2->nxt = temp;
temp->prv = temp2;
}
}
請定義 「撞車」。 – 2010-07-01 00:39:34
定義了哪個節點?任何原因,特別是你不使用'std :: list'(或者更好的'std :: vector')? – 2010-07-01 00:39:41
一個可能的錯誤:如果「(start_ptr = NULL)」將start_ptr設置爲NULL。我認爲你的意思是「if(start_ptr == NULL)」 – 2010-07-01 00:41:03