/**
 * A collection of methods related to int[].
 * NOTE: Try to use helper methods wherever you can!!
 */

public class ArrayStuff {


  /**
   * Print the contents of list[0..i-1] on one line, separated by commas
   * and spaces and surrounded by [ and ].
   */
  public static void print(int[] list, int i) {
    
    System.out.print("[");
    int k;
    for (k=0; k < i; k++){
      System.out.print(list[k] +", ");
    }
    
    System.out.print(list[k] + "]");
  }


  /**
   * Print the contents of the whole list on one line, separated by commas and spaces
   * and surrounded by [ and ].
   */
  public static void print(int[] list) {
    
    System.out.print("[");
    int i;
    for (i=0; i < list.length; i++){
      System.out.print(list[i] +", ");
    }
    
    System.out.print(list[i] + "]");
  }

  /**
   * NOTE: This uses the first print method as a helper method.
   * Print the contents of the whole list on one line, separated by commas and spaces
   * and surrounded by [ and ].
   */
  public static void print2(int[] list) {
    
    print(list, list.length);
  }


  /**
   * Return whether k is anywhere in list.
   */
  public static boolean contains(int[] list, int k) {
    
    for (int i=0; i < list.length; i++){
      if (list[i] == k){
        return true;
      }
    }
    return false;
  }
  
  /**
   * Return whether k is in list[][].
   * (That describes a rectangular portion of a two-dimensional array.)
   */
  public static boolean contains(
    int[][] list, int rowI, int rowJ, int colI, int colJ, int k) {
    
    for (int row=0; row < list.length; row++){
      for (int col=0; col < list[row].length; col++){
        if (list[row][col] == k){
          return true;
        }
      }
    }
    return false;
  }

  /**
   * NOTE: This uses the first contains method as a helper method.
   * Return whether k is in list[][].
   * (That describes a rectangular portion of a two-dimensional array.)
   */
  public static boolean contains2(
    int[][] list, int rowI, int rowJ, int colI, int colJ, int k) {

    for (int row=0; row < list.length; row++){
      if (contains(list[row],k) {
         return true;
	}
    }
    return exists;
  }
}

