Docsity

Arrays Exercise - Object-Oriented Programming II | CMSC 132, Assignments of Computer Science

Toggle sidebar
bg1
Arrays Exercise
Note: Your implementations must be as short and efficient as possible.
1. Write a method named isRagged that determines whether a two-dimensional array is a
ragged array. Remember, a ragged array is one where all the rows do not have the same
length.
2. Write a method named equals that determines whether two 2-dimensional arrays have the
same corresponding elements.
For example:
10, 20, 30 equals to 10, 20, 30
50, 40 50, 40
10, 30, 20 not equals to 10, 20, 30
50, 40, 60 40, 50, 60
10, 20, 30 not equals to 10, 20, 30
40, 50 40, 50, 60
60
3. Write a method named linearize that takes a 2-dimensional array as parameter and returns a
1-dimensional array with all the elements of the two-dimensional array.
For example, given the following array:
10, 20, 30
40, 50
60
The method will return a 1-dimensional array with the following elements:
10, 20, 30, 40, 50, 60
4. Write a method named isDeepCopy that determines whether a 2-dimensional array is a deep
copy of another array.

Partial preview of the text

Download Arrays Exercise - Object-Oriented Programming II | CMSC 132 and more Assignments Computer Science in PDF only on Docsity!

Arrays Exercise

Note: Your implementations must be as short and efficient as possible.

  1. Write a method named isRagged that determines whether a two-dimensional array is a ragged array. Remember, a ragged array is one where all the rows do not have the same length.
  2. Write a method named equals that determines whether two 2-dimensional arrays have the same corresponding elements.

For example:

10, 20, 30 equals to 10, 20, 30 50, 40 50, 40

10, 30, 20 not equals to 10, 20, 30 50, 40, 60 40, 50, 60

10, 20, 30 not equals to 10, 20, 30 40, 50 40, 50, 60 60

  1. Write a method named linearize that takes a 2-dimensional array as parameter and returns a 1-dimensional array with all the elements of the two-dimensional array.

For example, given the following array:

10, 20, 30 40, 50 60

The method will return a 1-dimensional array with the following elements:

10, 20, 30, 40, 50, 60

  1. Write a method named isDeepCopy that determines whether a 2-dimensional array is a deep copy of another array.