Lab 8: Manipulating arrays
It this lab, you will practice manipulating arrays. You are to create a single class that has the
following methods:
- print: Takes an array of int and prints its contents, separated by spaces,
to the screen.
- reverse: Takes an array of int and reverses the elements in it.
reverse should not create a new array.
int a[5] = {1, 2, 3, 4, 5};
reverse(a) => 5 4 3 2 1
- append: Takes two arrays of int and returns a new array that concatentates the
second array to the end of the first.
int a[5] = {1, 2, 3, 4, 5};
int b[3] = {10, 11, 12};
append(a, b) => 1 2 3 4 5 10 11 12
- interleave: Takes two arrays of int and returns a new array that interleaves the
elements of the two arrays.
int a[5] = {1, 2, 3, 4, 5};
int b[3] = {10, 11, 12};
interleave(a, b) => 1 10 2 11 3 12 4 5
- merge: A little more of a challenge for those who complete the above 4 quickly.
Take two arrays of int that are sorted and return a new array that contains the
elements of both arrays, sorted.
int a[5] = {3, 5, 6, 7, 10};
int b[4] = {1, 2, 8, 11};
merge(a, b) => 1 2 3 5 6 7 8 10 11
At the end of lab, email your class to your instructor, hsc@albion.edu.