n3
Properties
Next
Prev
n2
Properties
Next
Prev
n2
Properties
Next
Prev
n1
Properties
Next
Prev
>> removeNode(n2)
>> clear(n2)
MATLAB calls delete(n2)
Delete the List
When you create a linked list and assign a variable that contains, for example, the head or
tail of the list, clearing that variable causes the destructor to recurse through the entire
list. With large enough list, clearing the list variable can result in MATLAB exceeding its
recursion limit.
The clearList method avoids recursion and improves the performance of deleting large
lists by looping over the list and disconnecting each node. clearList accepts the handle
of any node in the list and removes the remaining nodes.
function clearList(node)
if ~isscalar(node)
error('Input must be scalar')
end
prev = node.Prev;
next = node.Next;
removeNode(node)
while ~isempty(next)
node = next;
next = node.Next;
3 MATLAB Classes Overview