Class ABinaryTreeIterator
Unit
classwork
Declaration
type ABinaryTreeIterator = class(AnIterator)
Description
Instances of this class can be used to iterate through the nodes in ABinaryTree and its descendants, starting with the root node and proceeding toward ABinaryTree.YoungestNode.
Nodes may be added and removed from the tree while the iterator is in use; the changes will be reflected by the iterator. The obvious exception to this rule is that the node represented by ABinaryTreeIterator.Current cannot be deleted until the iterator passes over it without causing program crashes. Likewise, the node directly attached to ABinaryTreeIterator.Current cannot be deleted or removed while ABinaryTreeIterator.next is operating (say, from a different thread). This is because we do not use reference counting or any other garbage collection routine to prevent the node from being deleted while the iterator is processing it. It is the responsibility of the programmer to know how program memory is being managed.
Hierarchy
Overview
Fields
Methods
Description
Fields
|
MyCurrentNode: ABinaryLeaf; |
Refers to the current node being processed
|
|
MyTree: ABinaryTree; |
Refers to the tree being processed
|
Methods
|
constructor over(const ThisTree: ABinaryTree); virtual; |
Construct an instance of ABinaryTreeIterator that will iterate over the nodes in ThisTree .
This method is called automatically by ABinaryTree.iterator, which is the preferred method for obtaining an instance of this class.
|
|
function init: boolean; override; |
Initializer
|
|
function continues: boolean; override; |
Determine whether or not there are more nodes over which to iterate. For more information on this routine, see AnIterator.continues.
|
|
procedure next; override; |
Retrieve the next node from the tree being processed.
If there are no more nodes (the iterator has reached the end of the tree), then this routine does nothing.
|
|
function shallowCopyFrom(const Other: AnObject): boolean; override; |
Construct a shallow copy of the other object.
This method overrides the behavior inherited from AnObject.shallowCopyFrom: it calls that method, then checks to see whether Other is an instance of ABinaryTreeIterator. If so, it copies the values of
from Other to Self , overwriting the values in Self .
|
|
function Current: ABinaryLeaf; virtual; |
Retrieve a reference to the most recent node retrieved from the tree.
The reference returned by this routine can be cast to a descendant of ABinaryLeaf if appropriate. The caller should know what type of node exists within the tree being processed.
The reference returned by this routine should NOT be freed by the caller.
|
|
function Tree: ABinaryTree; virtual; |
Retrieve a reference to the tree being processed.
The reference returned by this routine can be cast to a descendant of ABinaryTree if appropriate. The caller should know what type of tree is being processed by the iterator.
The reference returned by this routine should NOT be freed by the caller.
|
Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18
|