Pointer Variables and Dynamic Allocation







Pointers: The Problem





Pointers - The Problem



The Solution



Terminology





Introduction: Box Example





Java References: Class Box



Start with type Box



Introduce Type BoxPtr - And Allocate New Boxes



Access Fields: Dereference with .all (implicit allowed)



Refer to the Entire Box with .all



Some Type Checking



Some Things Never Change ...



Example with Integers



More Strong Typing



Can .all can be Omitted?



Sometimes .all is Required



Type BoxPtr: Another Example



Some Practice and Strong Typing





One Type in Java vs Two in Ada





Java and the Object Referenced



Java Comparison: Two Types vs One



Java Terminology: Two Types vs One





Dynamic Structures and Linked Lists





Problem and Solution



Dynamic Stacks and Queues



Types for Linked Structures - Version 1



Types for Linked Structures - Version 2



Making a List





Dynamic Stacks and Queues





A Dynamic Stack



An Empty Stack



A Dynamic Queue



Code for Dynamic Stacks and Queues



Class Exercises for Linked Structures





More Uses of Pointers





Pointers - The Problem - Revisited



Example Uses of Pointer



Accessing a Single Copy of a Value



Pointers to Arrays and Strings