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?