private static int[] maybeSort(int[] values){
  if (!isSorted(values,0,false)) {
    values=values.clone();
    Arrays.sort(values);
  }
  return values;
}

private static int [ ] maybeSort ( int [ ] values ) { if ( ! isSorted ( values , 0 , false ) ) { values = values . clone ( ) ; Arrays . sort ( values ) ; } return values ; }
clone and sort the array , if not already sorted .
