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.

• Calls auxiliary method visitRight(T, v, r), which performs the<br />

computations associated with encounter<strong>in</strong>g the node on the right<br />

• Returns r.out.<br />

Method templateEulerTour can be viewed as a template or "skeleton" of an<br />

Euler tour. (See Code Fragment 7.28.)<br />

<strong>Java</strong> Implementation<br />

<strong>Java</strong> class EulerTour, shown <strong>in</strong> Code Fragment 7.29, implements an Euler tour<br />

traversal us<strong>in</strong>g the template method pattern. The recursive traversal is performed<br />

by method eulerTour. The auxiliary methods called by eulerTour are<br />

empty place holders. That is, they have an empty body or they just return null.<br />

Class EulerTour is abstract <strong>and</strong> thus cannot be <strong>in</strong>stantiated. It conta<strong>in</strong>s an<br />

abstract method, called execute, which needs to be specified <strong>in</strong> the concrete<br />

subclass of EulerTour. Class TourResult, with fields left, right, <strong>and</strong><br />

out, is not shown.<br />

Code Fragment 7.29: <strong>Java</strong> class EulerTour<br />

def<strong>in</strong><strong>in</strong>g a generic Euler tour of a b<strong>in</strong>ary tree. This class<br />

realizes the template method pattern <strong>and</strong> must be<br />

specialized <strong>in</strong> order to get an <strong>in</strong>terest<strong>in</strong>g computation.<br />

427

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

Saved successfully!

Ooh no, something went wrong!