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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

We use a <strong>Java</strong> <strong>in</strong>terface BTPosition (not shown) to represent a node of a<br />

b<strong>in</strong>ary tree. This <strong>in</strong>terfaces extends Position, thus <strong>in</strong>herit<strong>in</strong>g method element,<br />

<strong>and</strong> has additional methods for sett<strong>in</strong>g the element stored at the node<br />

(setElement) <strong>and</strong> for sett<strong>in</strong>g <strong>and</strong> return<strong>in</strong>g the left child (setLeft <strong>and</strong><br />

getLeft), right child (setRight <strong>and</strong> getRight), <strong>and</strong> parent (setParent<br />

<strong>and</strong> getParent) of the node. Class BTNode (Code Fragment 7.15) implements<br />

<strong>in</strong>terface BTPosition by an object with fields element, left, right, <strong>and</strong> parent,<br />

which, for a node v, reference the element at v, the left child of v, the right child of<br />

v, <strong>and</strong> the parent of v, respectively.<br />

Code Fragment 7.15: Auxiliary class BTNode for<br />

implement<strong>in</strong>g b<strong>in</strong>ary tree nodes.<br />

403

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

Saved successfully!

Ooh no, something went wrong!