- #1
rootX
- 479
- 4
Following inserts new element at the list end.
The class has list_head, list_tail, and count ...
Problem: I don't know if node should be deleted or not.
The class has list_head, list_tail, and count ...
Problem: I don't know if node should be deleted or not.
Code:
//inserts an element at the end
template <typename Object>
void Single_list<Object>::push_back( const Object & obj ) {
//makes new node with value obj that has next element pointing
//to null
Single_node<Object> *node = new Single_node<Object>(obj,0);
//points the tail's next_node to the new node
list_tail->next_node = node;
//points list_tail to the new node
list_tail = node;
delete node;
count++;
}