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.

Class RBTree (Code Fragments 10.9 through 10.11) extends<br />

B<strong>in</strong>arySearchTree (Code Fragments 10.3 through 10.5). We assume the<br />

parent class supports the method restructure for perform<strong>in</strong>g tr<strong>in</strong>ode restructur<strong>in</strong>gs<br />

(rotations); its implementation is left as an exercise (P-10.3). Class RBTree<br />

<strong>in</strong>herits methods size, isEmpty, f<strong>in</strong>d, <strong>and</strong> f<strong>in</strong>dAll from B<strong>in</strong>arySearchTree<br />

but overrides methods <strong>in</strong>sert <strong>and</strong> remove. It implements these two operations by<br />

first call<strong>in</strong>g the correspond<strong>in</strong>g method of the parent class <strong>and</strong> then remedy<strong>in</strong>g any<br />

color violations that this update may have caused. Several auxiliary methods of<br />

class RBTree are not shown, but their names suggest their mean<strong>in</strong>gs <strong>and</strong> their<br />

implementations are straightforward.<br />

Code Fragment 10.10: The dictionary ADT method<br />

<strong>in</strong>sert <strong>and</strong> auxiliary methods createNode <strong>and</strong><br />

remedyDoubleRed of class RBTree.<br />

662

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

Saved successfully!

Ooh no, something went wrong!