hello. i have this section of code voidlist::remove_last() { list_node *cursor;
ID: 3610265 • Letter: H
Question
hello. i have this section of code voidlist::remove_last(){
list_node *cursor;
for (cursor = head_node; cursor -> next_node !=NULL; cursor = cursor -> next_node)
{
}
delete cursor ->next_node;
cursor -> next_node = NULL;
} runningwith this test code: void test_23()
{
cout << "Test remove_last" <<endl;
list l;
l.insert_first("001");
l.remove_last();
assert(l.length() == 0);
l.insert_first("001");
l.insert_last("002");
l.insert_last("003");
l.remove_last();
l.remove_first();
assert(l.length() == 1);
assert(l.get_first()->value == "002");
} and its failing the assert(l.length()==0); any clues to help me figure out why thatis? hello. i have this section of code voidlist::remove_last()
{
list_node *cursor;
for (cursor = head_node; cursor -> next_node !=NULL; cursor = cursor -> next_node)
{
}
delete cursor ->next_node;
cursor -> next_node = NULL;
} runningwith this test code: void test_23()
{
cout << "Test remove_last" <<endl;
list l;
l.insert_first("001");
l.remove_last();
assert(l.length() == 0);
l.insert_first("001");
l.insert_last("002");
l.insert_last("003");
l.remove_last();
l.remove_first();
assert(l.length() == 1);
assert(l.get_first()->value == "002");
} and its failing the assert(l.length()==0); any clues to help me figure out why thatis? runningwith this test code: void test_23()
{
cout << "Test remove_last" <<endl;
list l;
l.insert_first("001");
l.remove_last();
assert(l.length() == 0);
l.insert_first("001");
l.insert_last("002");
l.insert_last("003");
l.remove_last();
l.remove_first();
assert(l.length() == 1);
assert(l.get_first()->value == "002");
} and its failing the assert(l.length()==0); any clues to help me figure out why thatis? and its failing the assert(l.length()==0); any clues to help me figure out why thatis?
Explanation / Answer
//Hope this will helpyou.. I think you should check the constructor for the list classweather it is initating the length variable to zero or not. If it is zero then check in side insert function it isincrementing or not then check in remove function , is it decrementing ornot. ,still have problem then post the complete program.Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.