Question: Q2 (a) Type a C++ function named checkSecondHalf that takes an integer array and swaps the first half and the second half of the array.

Q2 (a) Type a C++ function named checkSecondHalf that takes an integer array and swaps the first half and the second half of the array.

Take this sample into account: When calling the function on array [4,5,6,1,2,3] will change it to [1,2,3,4,5,6]. Now, lets say if the total number of elements in the array is an odd number then the middle element should remain at its original position. For example, calling the function on array [12,18,3,5,7] will change it to [5,7,3,12,18]. Try using logic that is simple and easy to understand and avoid using other library functions.

Q2 (b) Type a C++ function named comesSecondLargest that returns the second largest element in the integer array. You may assume that all array elements are different.

Take this sample into account: if the array given is {-4,7,2,-12}, the function should return 2. Try using logic that is simple and easy to understand and avoid using other library functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!