public class ArrayStuff
{
  public static int max(int a[], int size)
  {
    int retval = a[0];
    
    for(int i = 1; i < size; i++)
    {
      if(a[i] > retval)
      {
        retval = a[i];
      }
    }
    return retval;
  }

  public static int min(int a[], int size)
  {
    int retval = a[0];
    
    for(int i = 1; i < size; i++)
    {
      if(a[i] < retval)
      {
        retval = a[i];
      }
    }
    return retval;
  }

  public static int find(int a[], int size, int target)
  {
    for (int i = 0; i < size; i++)
    {
      if(a[i] == target)
      {
        return  i;
      }
    }
    return  -1;
  }

  public static void sort(int a[], int n)
  {
    int pass;
    int temp;
    for(int pass = 0; pass < n-1; pass++)
    {
      for(int i = 0; i < n-1; i++)
      {
        if(a[i] > a[i+i])
        {
          temp = a[i];
          a[i] = a[i+1];
          a[i+1] = temp;
        }
      }
    }
  }
//if statement is executed (n-1)*(n-1) times = n^2 -2*n + 1
//execution time is roughly proportional to n^2

  

  public static void main(String args[])
  {
    int x[] = {1, 9, 3, 5, 7, 3, 4, 6};
    int big = max(x, 8);
    int small = min(x, 8);
    System.out.println("The biggest is " + big);
    System.out.println("The smallest is " + small);
    int where1, where2;
    where1 = find(x, 8, 3);
    where2 = find(x, 8, 15);
    System.out.println("3 was found in location " + where1);
    System.out.println("15 was found in location " + where2);

    
  }
}
