1 Playing with Puppers
Suppose we have the Dog and Corgi classes which are a defined below with a few
methods but no implementation shown. (modified from Spring ’16, MT1)
1 | 1 public class Dog { |
Suppose we have the Dog and Corgi classes which are a defined below with a few
methods but no implementation shown. (modified from Spring ’16, MT1)
1 | 1 public class Dog { |
Write a method flatten that takes in a 2D array x and returns a 1D array that
contains all of the arrays in x concatenated together.
(Summer 2016 MT1)
1 | public static int[] flatten(int[][] x) { |
As discussed in Monday’s lecture, an IntList is our CS61B implementation for a naked recursive linked list of integers. Each IntList has a first and rest variable. The first is the int element contained by the node, and the rest is the next chain in the list (another IntList!).
In the IntList directory for this lab, we’ve provided a much larger IntList.java than the one we created in class. It has five important new static methods, two of which you’ll fill in:
1.1 Given the Animal class, fill in the definition of the Cat class so that when greet()
is called, the label “Cat” (instead of “Animal”) is printed to the screen. Assume
that a Cat will make a “Meow!” noise if the cat is 5 years or older and “MEOW!”
if the cat is less than 5 years old.
1 | public class Animal { |
1 | public class SLList { |
1.1 Implement SLList.insert which takes in an integer x and inserts it at the given
position. If the position is after the end of the list, insert the new node at the end.
For example, if the SLList is 5 → 6 → 2, insert(10, 1) results in 5 → 10 → 6 → 2.