project and this is the approach i took, i don't know if it is
the right way to go or not. I created another function that traverse
through the list and delete all the remaining node before i delete the
actual List object. I know we have another function that searches the
list for a specified node to delete, but this other function i created
doesn't care what type of a node is in the List it wipes out every
node remaining in the list. But the tricky is you have to store the
current node into a temporary node, so that when you move on to the
next node thats when you delete whats behind, otherwise if you don't
do that then you will be trying to delete the current node causing the
current iteration of the List to break.
through the list and delete all the remaining node before i delete the
actual List object. I know we have another function that searches the
list for a specified node to delete, but this other function i created
doesn't care what type of a node is in the List it wipes out every
node remaining in the list. But the tricky is you have to store the
current node into a temporary node, so that when you move on to the
next node thats when you delete whats behind, otherwise if you don't
do that then you will be trying to delete the current node causing the
current iteration of the List to break.
-(void) gabageCollector
{
Loop (through the while p is not == null)
save p into a temporary pointer;
assign p to the next pointer;
then release the temporary pointer;
}
The after setting up the function, then i call it like this in main//go through the list and delete all remaining nodes
[newList gabageCollector];
//delete the List object
[newList release];
I don't know whether this is the right way to go but
thats the approach i took..
So long and stay thirst my friends........
No comments:
Post a Comment