Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 280 Data Structures Professor John Peterson. Phase 2 We’re moving on from array-based to link- based structures. You already have experience with links.

Similar presentations


Presentation on theme: "CS 280 Data Structures Professor John Peterson. Phase 2 We’re moving on from array-based to link- based structures. You already have experience with links."— Presentation transcript:

1 CS 280 Data Structures Professor John Peterson

2 Phase 2 We’re moving on from array-based to link- based structures. You already have experience with links but we’ll be doing some new things and exploring some advanced Java stuff as we beat linked structures to death …

3 Aliasing What is aliasing? The result of shared structure in your program. Many, many program bugs involve aliasing – we need to understand this thoroughly!

4 A Quiz class Link { public T data; public Link link = null; } a = new Link(); b = a; a.data = 1; b.data = 2; System.out.print(a.data);

5 Object Identity The big deal here is that we HAVE to understand the basic idea behind OO programming: identity. Java objects are divided into two classes: Primitive types (values only) Normal objects (objects with identity) What are the differences?

6 Types of Objects Primitive Compare values with == Never need to say “new” (no constructor) Fixed vocabulary Passed by value A “boxed type” is available – implicit coercion x = y copies value No internal structure Default depends on type Ordinary == compares identity, not values Always need to say “new” to make a value Can add user-defined classes Passed by reference x = y creates alias Contains instance vars Default is null

7 Representing Identity In the debugger, we see “Object numbers” to convey the idea of identity. In class, we deal with boxes and arrows. A box is an ordinary object A value (like 1.2 or null) is a primitive object – written as an ordinary value An object is represented by a arrow leading to a box Instance vars are components in a box Variables are names with either values or pointers

8 Example 5 null 7 ab Link Data

9 Example 5 null 7 ab Link Data Link a = new Link () a.data = b Link b = new Link () b.data = 7 a.link = b


Download ppt "CS 280 Data Structures Professor John Peterson. Phase 2 We’re moving on from array-based to link- based structures. You already have experience with links."

Similar presentations


Ads by Google