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.

$940. Write a program that takes as <strong>in</strong>put a sequence of transactions of the form<br />

"buy x; share(s) at $y each" or "sell x share(s) at $y<br />

each," assum<strong>in</strong>g that the transactions occur on consecutive days <strong>and</strong> the<br />

values x <strong>and</strong> y are <strong>in</strong>tegers. Given this <strong>in</strong>put sequence, the output should be the<br />

total capital ga<strong>in</strong> (or loss) for the entire sequence, us<strong>in</strong>g the FIFO protocol to<br />

identify shares.<br />

Chapter Notes<br />

We were <strong>in</strong>troduced to the approach of def<strong>in</strong><strong>in</strong>g data structures first <strong>in</strong> terms of their<br />

ADTs <strong>and</strong> then <strong>in</strong> terms of concrete implementations by the classic books by Aho,<br />

Hopcroft, <strong>and</strong> Ullman [4, 5], which <strong>in</strong>cidentally is where we first saw aproblem<br />

similar to Exercise C-5.6. Exercises C-5.10, C-5.11, <strong>and</strong> C-5.12 are similar to<br />

<strong>in</strong>terview questions said to be from a well-known software company. For further<br />

study of abstract data types, see Liskov <strong>and</strong> Guttag [69], Cardelli <strong>and</strong> Wegner [20], or<br />

Demurjian [28].<br />

Chapter 6<br />

Lists <strong>and</strong> Iterators<br />

Contents<br />

6.1<br />

Array Lists ......................<br />

222<br />

6.1.1<br />

The Array List Abstract <strong>Data</strong> Type..........<br />

222<br />

6.1.2<br />

The Adapter Pattern.................<br />

310

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

Saved successfully!

Ooh no, something went wrong!