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 beg<strong>in</strong> with the array implementation, which we show <strong>in</strong> Code Fragment 11.1.<br />

We illustrate a step <strong>in</strong> the merge of two sorted arrays <strong>in</strong> Figure 11.5.<br />

Code Fragment 11.1: Algorithm for merg<strong>in</strong>g two<br />

sorted array-based sequences.<br />

Figure 11.5: A step <strong>in</strong> the merge of two sorted arrays.<br />

We show the arrays before the copy step <strong>in</strong> (a) <strong>and</strong><br />

after it <strong>in</strong> (b).<br />

Merg<strong>in</strong>g Two Sorted Lists.<br />

In Code Fragment 11.2, we give a list-based version of algorithm merge, for<br />

merg<strong>in</strong>g two sorted sequences, S 1 <strong>and</strong> S 2 , implemented as l<strong>in</strong>ked lists. The ma<strong>in</strong><br />

684

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

Saved successfully!

Ooh no, something went wrong!