Summary

We looked at another common data structure called a deque. A deque is a double-ended queue, so insertions and deletions are possible at both ends. We looked at pushFront, popFront, pushBack, and popBack operations. We also looked at some applications of deques.

Deques have a simple implementation in the imperative world. A doubly linked list could be used for implementing it. A vector could be used too.

We looked at two important concepts: amortization and lazy evaluation. We took a detailed look at Scala's Streams. We saw what a thunk is and how it helps us with delayed evaluation.

We then used all these concepts to check whether we can create more efficient queues. As we saw in the previous chapter, reversing an in list and appending it ...

Get Learning Functional Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.