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.

5.4 Exercises<br />

For source code <strong>and</strong> help with exercises, please visit<br />

java.datastructures.net.<br />

Re<strong>in</strong>forcement<br />

R-5.1<br />

Suppose an <strong>in</strong>itially empty stack S has performed a total of 25 push operations,<br />

12 top operations, <strong>and</strong> 10 pop operations, 3 of which generated<br />

StackEmptyExceptions, which were caught <strong>and</strong> ignored. What is the current<br />

size of S?<br />

R-5.2<br />

If we implemented the stack S from the previous problem with an array, as<br />

described <strong>in</strong> this chapter, then what is the current value of the top <strong>in</strong>stance<br />

variable?<br />

R-5.3<br />

Describe the output of the follow<strong>in</strong>g series of stack operations: push(5),<br />

push(3), pop(), push(2), push(8), pop(), pop(),<br />

push(9), push(1), pop(), push(7), push(6), pop(),<br />

pop(), push(4), pop(), pop().<br />

R-5.4<br />

Give a recursive method for remov<strong>in</strong>g all the elements <strong>in</strong> a stack.<br />

R-5.5<br />

Give a precise <strong>and</strong> complete def<strong>in</strong>ition of the concept of match<strong>in</strong>g for group<strong>in</strong>g<br />

symbols <strong>in</strong> an arithmetic expression.<br />

R-5.6<br />

Describe the output for the follow<strong>in</strong>g sequence of queue operations:<br />

enqueue(5), enqueue(3), dequeue(), enqueue(2),<br />

enqueue(8), dequeue(), dequeue(), enqueue(9),<br />

enqueue(1), dequeue(), enqueue(7), enqueue(6),<br />

dequeue(), dequeue(), enqueue(4), dequeue(),<br />

dequeue().<br />

R-5.7<br />

305

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

Saved successfully!

Ooh no, something went wrong!