Кажется, я не могу понять, почему цикл while не заканчивается.C++: В то время как цикл не заканчивается как NULL, я что-то упускаю?
Должно быть в то время как (null) в основном.
Я не могу понять это.
Вся помощь будет оценена: D
Я не знаю, что могло бы быть останавливая время цикла на всех? В нем говорится, что первая запись сохраняется, а запись для следующего - 0x0000000000 и ??? имя и ??? ??? так что это на самом деле NULL. Я попытался добавить в конструктор next = 0; вместо next = NULL, и это все еще не сработало.
Спасибо, ребята.
Энтони
EDIT: Value of nodePtr = 00000000 if next = 0 in the constructor
Value of nodePtr = 00899FE0 if next = NULL in the constructor
if adding a cout << nodePtr->next; before the while.
http://pastebin.com/7usYdfHB - Полная программа для справки.
EDIT2: Является ли всплывающее окно, когда я иду, чтобы ввести вторую запись.
void LinkedList::appendNode(string name, double x, double y)
{
ListNode* newNode; // To point to new node
ListNode* nodePtr; // To traverse List
// allocate new node
newNode = new ListNode(name, x, y);
// If no head, head is the newNode
// else traverse the list to find the end and append newNode
if (!head)
{
head = newNode;
cout << "Record inserted successfully.\n" << endl;
}
else
{
nodePtr = head;
//traverse the list loop
while (nodePtr->next) //VS 2012 locks up here <-----
{
//Checks for duplicate entry by name
if (nodePtr->cityName == name)
{
cout << "No need to insert again, as this record exists in the existing data set.\n" << endl;
return;
}
//traverse the list
nodePtr = nodePtr->next;
}
// checks 2nd entry, as while loop wont run for a 2nd entry.
if (nodePtr->cityName == name) {
{
cout << "No need to insert again, as this record exists in the existing data set.\n" << endl;
return;
}
}
// if next is NULL add newNode
else if (!nodePtr->next)
{
nodePtr->next = newNode;
cout << "Record inserted successfully.\n" << endl;
}
}
Вы инициализируетесь рядом с NULL в своем конструкторе для ListNode? – drescherjm
Опубликовать конструктор. Собственно, отправьте два из них: один из «LinkedList» и еще один из «ListNode». – AnT
http://pastebin.com/7usYdfHB – user2565679