I need to compute the peek mid element also the problem statement for implementing this method is as follows:-
*returns object which has the middle value among the all objects without removing it from the stack.
*returns the object which has the value of following order (size()/2)+1
*e.g. *When the stack has the following values (1, 2, 5, 4, 2, 6) *this method returns 4 and doesn't remove the object.
so my query is:-
should i consider the middle element in terms of position i.e. after sorting the elements of the stack the mid element is obtained as mid = stack[size()/2+1]
or should i consider it in terms of value i.e. mid= max+min/2
as in above problem both the situations are correct( in my point of view) i.e.
stack[size()/2+1]=stack[6/2+1]=4
and max+min/2=6+1/2=3.5
and rounding off will be equal to 4
kindly help me understanding the problem statement