rearrange
Category: Programming
Author: Stuart Reges
Book Chapter: 7.2
Problem: rearrange
Write a static method rearrange that takes an array of integers as an argument and that rearranges the values so that all of the multiples of 3 come first followed by numbers that are one greater than a multiple of 3 followed by numbers that are two greater than a multiple of 3. For example, if a variable called "list" stores this sequence of values: (23, 12, 8, 0, 4, 80, 9, 7, 30, 99, 50, 42, 13, 47, 2, 16, 87, 75) Then the following call: rearrange(list); Should rearrange the values to look something like this: (12, 0, 9, 30, 99, 42, 87, 75, 4, 13, 16, 7, 23, 47, 2, 50, 8, 80) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ multiples of 3 1 more than a 2 more than a multiple of 3 multiple of 3 This is only one possible arrangement. Any arrangement that puts the multiples of 3 first followed by the values that are one more than a multiple of 3 followed by the values that are two more than a multiple of 3 is acceptable. You are not allowed to use an auxiliary data structure such as a temporary array or ArrayList to solve this problem. You may assume that all values in the array are greater than or equal to 0. Write your solution to rearrange below.