Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java (a) Write the Mountain method get PeakIndex. Method get PeakIndex returns the index of the first peak found in the parameter array, if one
Java
(a) Write the Mountain method get PeakIndex. Method get PeakIndex returns the index of the first peak found in the parameter array, if one exists. A peak is defined as an element whose value is greater than the value of the element immediately before it and is also greater than the value of the element immediately after it. Method get Peak Index starts at the beginning of the array and returns the index of the first peak that is found or -1 if no peak is found. For example, the following table illustrates the results of several calls to get PeakIndex. arr get PeakIndex (arr) 2 1 -1 [11, 22, 33, 22, 11) (11, 22, 11, 22, 11) (11, 22, 33, 55, 77) (99, 33, 55, 77, 1201 {99. 33. 55, 77, 55) (33, 22, 11) -1 3 -1 Complete method get Peak Index below. /** @param array an array of positive integer values Precondition: array.length > 0 Greturn the index of the first peak (local maximum) in the array, if it exists: I otherwise public static int get PeakIndex (int[] array)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started