Hi
i have to use linked lists to get information from the user and dispaly it. I am having trouble with displaying the linked list. If you look at my second function where i am trying to list the information, you might be able to tell what the problem is? because when i run it, temp is never equal to 0 and the loop keeps running. The temp should equal to 0 when it reaches the empty part of the list.
Please help. Thanks
void CD::create_cd () {
start_ptr = NULL;
temp = new DVD;
cout << "\nPlease enter the title of the CD: ";
cin >> temp->title;
temp->next = NULL;
// Set up link to this node
if (start_ptr == NULL)
{start_ptr = temp;}
else
{temp2 = start_ptr;
while (temp2->next != NULL) { temp2 = temp2->next; }
temp2->next = temp; }
}
void CD::list()
{
do
{ if (temp == NULL)
cout << "End of list" << endl;
else
{
cout<<"Title: "<<temp->title<<endl;
// Move to next node (if present)
temp = temp->next; [B]//this should make temp=NULL eventually
[/B] }
}
[B]while (temp != NULL); //Problem here!!![/B]
}