M
mfactor
Hello group,
I've created a linked list with a node class and a list class, and to
search the list, I use a pointer like this:
node * current = getFirst();
where getFirst() return the first node on the list. It works fine. My
doubt is about memory allocation: with this, I think I've just
referenced the pointer current to the address of the pointer to the
first node on the list. Do I need to call delete on the end of the
method?
class node {
node * first;
....
}
node* node::getFirst() {
return first;
}
somewhere in the code...
void list::search() {
node * current = getFirst();
while(current != NULL) {
//do stuff
}
}
I've created a linked list with a node class and a list class, and to
search the list, I use a pointer like this:
node * current = getFirst();
where getFirst() return the first node on the list. It works fine. My
doubt is about memory allocation: with this, I think I've just
referenced the pointer current to the address of the pointer to the
first node on the list. Do I need to call delete on the end of the
method?
class node {
node * first;
....
}
node* node::getFirst() {
return first;
}
somewhere in the code...
void list::search() {
node * current = getFirst();
while(current != NULL) {
//do stuff
}
}