Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Swapper
- {
- /**
- This method swaps adjacent elements of the given array
- @param values an array
- */
- public void swap(int[] values, int first, int second)
- {
- int temp = values[first];
- values[first] = values[second];
- values[second] = temp;
- }
- public void swapAdjacentElements(int[] values)
- {
- for(int i = 0; i < values.length; i++)
- {
- swap(values, i, ++i);
- if(i + 2 > values.length - 1){break;}
- }
- }
- // This method is used to check your work
- public int[] check(int[] values)
- {
- swapAdjacentElements(values);
- return values;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement