CS 145 Lecture 30 – Higher Dimensions
Agenda
- what ?s
- arraylistercise
- arrays to higher dimensions
TODO
- Read sections 7.3 through 7.5 in the book. Share 2-3 questions or observations on a 1/4 sheet.
- Start homework 6. Due before November 30.
- The challenge for the second and final mercy fortnight will involve finishing homework 7 on objects before December 7. The regular due date will be before December 14. Homework 7 will be released before break and achieving it will give you the opportunity to resubmit homeworks 4, 5, and 6 before the final exam.
Note
Last time we looked at managing “growable” arrays with the ArrayList
class:
1: ...
Now, we missed a blackbox the other day that grows our idea of arrays into higher dimensions. Let’s have look:
To solve this we need to make arrays in higher dimensions. We saw the general pattern for making an array:
type[] id = new type[n];
The type can be anything, even another array. Suppose we want an array of int
arrays? Then we substitute int[]
in for type:
int[][] id = new int[outerN][innerN];
We’ll look at two-dimensional arrays through the lens of the birthday problem and generating all prefixes of an array.
Code
Prefices.java
/usr/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'coderay' (>= 0) among 56 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/.gem/ruby/2.7.0:/var/lib/gems/2.7.0:/usr/lib/ruby/gems/2.7.0:/usr/share/rubygems-integration/2.7.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0:/home/johnch/.gems', execute `gem env` for more information from /usr/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec' from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem' from ./coderay:24:in `'
Bepeats.java
/usr/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'coderay' (>= 0) among 56 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/.gem/ruby/2.7.0:/var/lib/gems/2.7.0:/usr/lib/ruby/gems/2.7.0:/usr/share/rubygems-integration/2.7.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0:/home/johnch/.gems', execute `gem env` for more information from /usr/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec' from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem' from ./coderay:24:in `'