Skip to Main Content Skip to Search
Product Documentation

allnodes - Tree nodes

Syntax

N = allnodes(T)
N = allnodes(T,'deppos')

Description

allnodes is a tree management utility that returns one of two node descriptions: either indices, or depths and positions.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

N = allnodes(T) returns the indices of all the nodes of the tree T in column vector N.

N = allnodes(T,'deppos') returns the depths and positions of all the nodes in matrix N.

N(i,1) is the depth and N(i,2) the position of the node i.

Examples

% Create initial tree. 
ord = 2;
t = ntree(ord,3);    % Binary tree of depth 3. 
t = nodejoin(t,5); 
t = nodejoin(t,4); 
plot(t)

% Change Node Label from Depth_Position to Index
% (see the plot function).

% List t nodes (index).
aln_ind = allnodes(t)
aln_ind =
    0 
    1 
    2 
    3 
    4 
    5 
    6 
    7 
    8 
   13 
   14
% List t nodes (Depth_Position). 
aln_depo = allnodes(t,'deppos')
aln_depo =
    0   0
    1   0
    1   1
    2   0
    2   1
    2   2
    2   3
    3   0
    3   1
    3   6
    3   7
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS