了解栈的实现问题的声明 [英] Understanding Stack implementation problem statement
问题描述
我需要计算偷看中间元件也问题陈述用于实现该方法如下: -
I need to compute the peek mid element also the problem statement for implementing this method is as follows:-
*回报对象,它有中的所有对象的中间值,而不从栈中删除。
*返回其具有下列顺序(尺寸()/ 2)1的值的对象
*例如。 *当堆栈具有以下值(1,2,5,4,2,6)*此方法返回4和不删除该对象。
*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:-
我应该考虑的排序堆的中间元素获得元素中旬以后=栈[尺寸()/ 2 + 1] $ C $的位置,即计算中间元素C>
或者我应该考虑它的价值计算,即
中期= MAX +分/ 2
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.
栈[尺寸()/ 2 + 1] =堆栈[6/2 + 1] = 4
和 MAX +分/ 2 = 6 + 1/2 = 3.5
和四舍五入将等于4
and max+min/2=6+1/2=3.5
and rounding off will be equal to 4
好心帮我理解问题陈述
推荐答案
一个堆栈是一个数据结构,因此在最一般的情况下应当能够存储任何类型的数据。你正在处理int类型时,这只是一个简化您的任务。数据结构明智的,它使您考虑中间元素,而不是执行的元素值的任何计算(即太具体的数据结构)的感觉。
A stack is a data structure, and as such in the most generic case should be able to store any data type. The fact that you are dealing with ints is just a simplification for your assignment. Data structure wise, it makes sense that you consider the middle element, and not perform any computation on element values (that is too specific for a data structure).
好像你想要的是在((N / 2)+ 1)个元件,所以在本实施例折射率(n / 2)元素
It seems like what you want is the ((n/2) + 1) th element, therefore the element at index (n/2) in this example.
这篇关于了解栈的实现问题的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!