Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- int getMaxElement(int* elementsArr, int startingPoint, int endingPoint) {
- int middleIndex = endingPoint - (endingPoint + startingPoint)/2;
- if (middleIndex == 0) {
- if (elementsArr[startingPoint] > elementsArr[endingPoint])
- return elementsArr[startingPoint];
- else
- return elementsArr[endingPoint];
- }
- if (getMaxElement(elementsArr, startingPoint + middleIndex, endingPoint) > getMaxElement(elementsArr, startingPoint, endingPoint - middleIndex))
- return getMaxElement(elementsArr, startingPoint + middleIndex, endingPoint);
- else
- getMaxElement(elementsArr, startingPoint, endingPoint - middleIndex);
- }
- int main() {
- int arr[10] = { 1, 2, 12, 22, -1, 3, -2, 7, 0, 12 };
- std::cout << getMaxElement(arr, 0, 9);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement