23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Code Fragment 7.21: Algorithm<br />

buildExpression.<br />

Preorder Traversal of a B<strong>in</strong>ary Tree<br />

S<strong>in</strong>ce any b<strong>in</strong>ary tree can also be viewed as a general tree, the preorder traversal<br />

for general trees (Code Fragment 7.8) can be applied to any b<strong>in</strong>ary tree. We can<br />

simplify the algorithm <strong>in</strong> the case of a b<strong>in</strong>ary tree traversal, however, as we show<br />

<strong>in</strong> Code Fragment 7.22.<br />

Code Fragment 7.22: Algorithm b<strong>in</strong>aryPreorder<br />

for perform<strong>in</strong>g the preorder traversal of the subtree of<br />

a b<strong>in</strong>ary tree T rooted at a node v.<br />

418

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!