removeNode(node);
end
while ~isempty(prev)
node = prev;
prev = node.Prev;
removeNode(node)
end
end
For example, suppose that you create a list with many nodes:
head = dlnode(1);
for k = 100000:-1:2
nextNode = dlnode(k);
insertAfter(nextNode,head)
end
The variable head contains the handle to the node at the head of the list:
head
head =
dlnode with properties:
Data: 1
Next: [1x1 dlnode]
Prev: []
head.Next
ans =
dlnode with properties:
Data: 2
Next: [1x1 dlnode]
Prev: [1x1 dlnode]
You can call clearList to remove the whole list:
clearList(head)
The only nodes that have not been deleted by MATLAB are those nodes for which there
exists an explicit reference. In this case, those references are head and nextNode:
Implementing Linked Lists with Classes