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