Chapter 4: Stacks and Queues

4.2 Stack

4.2.1 The Stack ADT Abstract Data Types (ADTs) Exceptions
4.2.2 A Simple Array-Based Implementation

Algorithm size()
    return t + 1

Algorithm pop()
    if isEmpty() then
        throw EmptyStackException
    else
        tt − 1
        return S[t +1]
Algorithm push(o)
    if t = S.length − 1 then
        throw FullStackException
    else
        tt + 1
        S[t] ← o




4.3 Queues

4.3.1 The Queue ADT
4.3.2 A Simple Array-Based Implementation
Queue Operations:

Algorithm size()
    return (Nf + r) mod N

Algorithm isEmpty()
    return (f = r)
Algorithm enqueue(o)
    if size() = N − 1 then
        throw FullQueueException
    else
        Q[r] ← o
        r ← (r + 1) mod N

Algorithm dequeue()
    if isEmpty() then
        throw EmptyQueueException
    else
        oQ[f]
        f ← (f + 1) mod N
        return o

4.4 Linked Lists

4.4.1 Singly Linked Lists




4.4.2 Implementing a Stack with a Singly Linked List 4.4.3 Implementing a Queue with a Singly Linked List

4.5 Double-Ended Queue (Deque)

Supports insertion and deletion at both the front and the rear of the queue.

4.5.1 The Deque ADT
4.5.2 Implementing a Deque with a Doubly Linked List
4.5.3 The Adapter Design Pattern