【发布时间】:2014-11-14 12:26:56
【问题描述】:
这是我遇到的一个竞争性测验问题。而且我对提供的答案不满意。
A single array A[1..MAXSIZE] is used to implement two stacks.
The two stacks grow from opposite ends of the array.
Variables top1 and top 2 (top1< top 2)
point to the location of the topmost element in each of the stacks.
If the space is to be used efficiently, the condition for “stack full” is
(a) (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
(b) top1 + top2 = MAXSIZE
(c) (top1 = MAXSIZE/2) or (top2 = MAXSIZE)
(d) top1 = top2 -1
我的逻辑是从两端开始,因此我选择了答案 (b),但测验已将答案 (d) 标记为正确。我错过了什么?
谢谢。
【问题讨论】:
标签: arrays data-structures stack