Mountain

public class Mountain {
/*
@param array: an array of positive integer values
@param stop: the last index to check
Precondition: 0 <= stop < array.length
@return true if for each j such that 0<=j<stop, array[j] < array[j+1];
false otherwise.
*/
public static boolean isIncreasing(int[] array, int stop) {
for(int i=0; i<stop; i++) {
/*if previous value is no less than the latter,
return false since it doesn't increase continuously.
*/
if(array[i] >= array[i+1]) return false;
}
return true;
}
/*
@param array: an array of positive integer values
@param start: the first index to check
Precondition: 0 <= start < array.length-1
@return true if for each j such that start<=j<array.length-1, array[j] > array[j+1];
false otherwise.
*/
public static boolean isDecreasing(int[] array, int start) {
return false;
}
/*
@param array: an array of positive values
Precondition: array.length > 0
@return the index of the first peak(local maximum) in the array, if it exists; -1 otherwise.
*/
public static int getPeakIndex(int[] array) {
return -1;
}
/*
@param array: an array of positive integer values
Precondition: array.length > 0
@return true if array contains values ordered as a mountain; false otherwise.
*/
public static boolean isMountain(int[] array) {
return false;
}
}Part(1)
Parameters
isDecreasing(arr, start)
Part(2)

Part(3)

TEST
Last updated