









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the cs61b lecture notes on containers in java. It covers the basics of values and containers, pointers, and the difference between destructive and non-destructive operations. It also explains how to define new types of objects using class declarations and provides examples of primitive operations and destructive vs. Non-destructive methods.
Typology: Slides
1 / 15
This page cannot be seen from the preview
Don't miss anything!










3 ’a’ true
x: 3 L: p:
Examples: variables, fields, individual array elements, parameters.
h t
h: 3 t:
0 17
1 9
2
Class Object Array Object Empty Object
Alternative Notation
p: 3
h t 7
h t
simple container (local variable)
structured containers (anonymous)
named simple containers (fields) within structured containers
unchanged, as shown on the left. A destructive method may modify the input objects, so that the original data is no longer available, as shown on the right:
Easier to build things first-to-last, unlike recursive version:
static IntList incrList (IntList P, int n) { if (P == null) return null; IntList result, last; result = last = new IntList (P.head+n, null); while (P.tail != null) { P = P.tail; last.tail = new IntList (P.head+n, null); last = last.tail; } return result; }
Easier to build things first-to-last, unlike recursive version:
static IntList incrList (IntList P, int n) { if (P == null) return null; IntList result, last; result = last = new IntList (P.head+n, null); while (P.tail != null) { P = P.tail; last.tail = new IntList (P.head+n, null); last = last.tail; } return result; }
last:
result: 5
Easier to build things first-to-last, unlike recursive version:
static IntList incrList (IntList P, int n) { if (P == null) return null; IntList result, last; result = last = new IntList (P.head+n, null); while (P.tail != null) { P = P.tail; last.tail = new IntList (P.head+n, null); last = last.tail; } return result; }
last:
result: 5 45
Easier to build things first-to-last, unlike recursive version:
static IntList incrList (IntList P, int n) { if (P == null) return null; IntList result, last; result = last = new IntList (P.head+n, null); while (P.tail != null) { P = P.tail; last.tail = new IntList (P.head+n, null); last = last.tail; } return result; }
last:
result: 5 45
Easier to build things first-to-last, unlike recursive version:
static IntList incrList (IntList P, int n) { if (P == null) return null; IntList result, last; result = last = new IntList (P.head+n, null); while (P.tail != null) { P = P.tail; last.tail = new IntList (P.head+n, null); last = last.tail; } return result; }
last:
result: 5 45 58