void my_int_sllist::pop_back()
{
//head and tail pointers
cout<<"enter pop_back";
//contains one node
if(head==tail)
{
cout<<"enter head==tail?";
delete head;
head=tail=0;
siz--;
}
else
{
cout<<"enter's other condition";
my_int_node* temp;
for(temp=head; temp->next!=tail; temp=temp->next)
{
delete tail;
tail=temp;
tail->next=0;
}
siz--;
}
}
lotrsimp12345
37
Posting Pro in Training
Recommended Answers
Jump to PostHow many nodes do you want to delete? Line 19 deletes a node every time it goes through the for-loop. If you only want to delete one node, don't stick "delete" in a loop.
Jump to Postfor(temp=head; temp->next!=tail; temp=temp->next) { tail=temp; tail->next=0; }
Same problem as before. How many pointers need to be set to null? One? Then it shouldn't be inside of a loop.
Jump to Postany hints as to how to fix this?
Anything that happens once doesn't happen every time you go through a loop. Anything that happens roughly once per node goes in a loop. Your task, not necessarily in this order:
- Find the tail.
- Delete the tail.
- Find anything that points to …
All 10 Replies
VernonDozier
2,218
Posting Expert
Featured Poster
lotrsimp12345
37
Posting Pro in Training
lotrsimp12345
37
Posting Pro in Training
VernonDozier
2,218
Posting Expert
Featured Poster
lotrsimp12345
37
Posting Pro in Training
VernonDozier
2,218
Posting Expert
Featured Poster
lotrsimp12345
37
Posting Pro in Training
lotrsimp12345
37
Posting Pro in Training
lotrsimp12345
37
Posting Pro in Training
lotrsimp12345
37
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.