-
Notifications
You must be signed in to change notification settings - Fork 11
/
question14.c
33 lines (21 loc) · 1.35 KB
/
question14.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
You are given an array "A" of "n" integers. It is given that the elements of "A" satisfy the following inequalities:
A[0] < A[1] < ... < A[m - 1] < A[m] > A[m + 1] > A[m + 2] > ... > A[n - 1]
for some (unknown) index "m" in the range [1,n-2].
Let us call such an array a "hill-valued" array. The sequence A[0], A[1], ... , A[m - 1], A[m]
is called the "ascending part" of the hill, and the remaining part A[m], A[m+1], . . ., A[n - 1] is called the
"descending part" of the hill. The element A[m] is the "peak" of the hill and is the
largest element in the array. Your task is to locate the peak, i.e., to determine the values of "m" and "A[m]".
Write a C function "int binarysearchpeak (int array[], int first_index, int last_index)"
to perform the task, by performing a (non-recursive) binary search. The initial call to the function is of the form
"m = binarysearchpeak(A, 0, n-1)" where "A" is a hill-valued array holding "n" integers. The function returns the
value of "m". Write a complete C program to demonstrate the working of the function. You might
have a hard-coded hill-valued array of (say) 10 integers inside your "main()" body.
Input: Nothing
Output : the value of "m" and the value of "A[m]", printed from inside "main()". [3]
*/
#include <stdio.h>
void is_palindrome(int a){
}
int main(){
}