// Allison Obourn
// CS& 141, Winter 2021
// Lecture 12

// This program creates three arrays and demonstrates the results of swapping values at 
// indecies in these arrays and swapping the contents of whole arrays.

import java.util.*;

public class Reverse {
   public static void main(String[] args) {
      int[] list = {1, 2, 3, 4, 5};
      swap(list, 1, 2);
      System.out.println(Arrays.toString(list));
      
      int[] list2 = {1, 2, 3};
      int[] list3 = {123, 54, 8};
      swapAll(list2, list3);
      System.out.println(Arrays.toString(list2));
      System.out.println(Arrays.toString(list3));

   }
   
   // Takes two arrays as parameters and swaps all of the values in the first with 
   // all the values in the second. Assumes that both arrays are the same length and not null. 
   // The values will end up in the same order as they originally were in
   public static void swapAll(int[] a1, int[] a2) {
      for(int i = 0; i < a1.length; i++) {
         int temp = a1[i];
         a1[i] = a2[i];
         a2[i] = temp;
      }
   }
   
   // Takes an array and two indecies as parameters. Assumes that the array isn't null and that
   // both indecies are between 0 and less than the length of the array. Swaps the values
   // in the array at the indecies. 
   public static void swap(int[] array, int first, int second) {
      int temp = array[first];
      array[first] = array[second];
      array[second] = temp;
   }
}