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 B<strong>in</strong>arySearchTree uses location-aware entries (see Section 8.4.2). Thus,<br />

its update methods <strong>in</strong>form any moved BSTEntry objects of their new positions.<br />

We also use several simple auxiliary methods for access<strong>in</strong>g <strong>and</strong> test<strong>in</strong>g data, such as<br />

checkKey, which checks if a key is valid (albeit us<strong>in</strong>g a fairly simple rule <strong>in</strong> this<br />

case). We also use an <strong>in</strong>stance variable, actionPos, which stores the position<br />

where the most recent search, <strong>in</strong>sertion, or removal ended. This <strong>in</strong>stance variable is<br />

not necessary to the implementation of a b<strong>in</strong>ary search tree, but is useful to classes<br />

that will extend B<strong>in</strong>arySearchTree (see Code Fragments 10.7, 10.8, 10.10, <strong>and</strong><br />

10.11) to identify the position where the previous search, <strong>in</strong>sertion, or removal has<br />

taken place. Position action Pos has the <strong>in</strong>tended mean<strong>in</strong>g provided it is used<br />

right after execut<strong>in</strong>g the method f<strong>in</strong>d, <strong>in</strong>sert, or remove.<br />

Code Fragment 10.3: Class B<strong>in</strong>arySearchTree.<br />

(Cont<strong>in</strong>ues <strong>in</strong> Code Fragment 10.4.)<br />

593

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

Saved successfully!

Ooh no, something went wrong!