Chapter 13: Object-Based Abstractions
Chapter 13: Object-Based Abstractions
Course Summary
Abstractions of State
Examples of Modifiable Objects
Arithmetic Expressions Revisited
Operator Precedence
Using Precedence Rules
Evaluating Expressions According to Precedence Rules
Using an Expression Stack
Expression Stack Trace
Describing the Expression Evaluator
Why the Element Below the Top Is Needed
Another Scenario
An Action Table for Unparenthesized Expressions
Adding Parentheses to the Evaluation Method
Stack Trace With Parentheses
An Action Table With Parentheses
Implementing the Evaluator
RA-stack Operations in Scheme
The evaluate Procedure
The process Procedure
Deciding When to Accept
Deciding When to Reduce
Deciding When to Shift
Reducing the Stack
The reduce! Procedure
Utility Procedures
Example Calls
Data Abstraction Revisited
Axioms for RA-Stacks
Implementation Requirements
Programming Paradigms
Vectors (Section 11.6)
Vector Example 1
Vector Example 2
Two-Vector Implementation of RA-Stacks
Trade-Offs
RA-Stack Creation
RA-Stack Height and Emptiness
Advertised and Unadvertised RA-Stack Operations
RA-Stack Access
The top-minus Procedure
pop!
push!
Stack Overflow
One Solution
Another Solution
An ADT for Nodes
Implementing RA-Stacks Using Nodes
RA-Stack Access
Trade-Offs Again
RA-Stack Mutation: Popping
RA-Stack Mutation: Pushing
Node Mutation
pop!
push!
Back to the Expression Evaluator
Yet Another RA-Stack Representation
Cons Mutators
Mutable Pairs in Racket
Back to Yet Another RA-Stack Representation
Data Abstraction
LIFO vs. FIFO
Operations for the Queue ADT
A Suboptimal Queue Representation
Shifting Queue Elements
A Better Queue Representation
Change Start Location, Don't Move Data
End of the Vector
Circular Queues
A New Representation Invariant
Calculating an Enqueued Item's Location
Calculating the Start Location After a Dequeue
Queue ADT Implementation
A Linked-List Queue Representation