问题描述
如果第一个堆栈元素放在最后一个数组元素(索引小于数组长度)而不是第一个数组元素(索引0),那么空堆栈和完整堆栈的测试会如何变化? (绘制堆栈图片会有所帮助)
A.空:顶部==长度;满:顶部== 0
B.空:顶部== 0;满:顶部==长度
C.空:顶部==长度;满:顶部== -1
D.空:顶部==长度-1;满:顶部== 0
我尝试过:
不确定哪个是对的。这是一个简单的多项选择题,但没有一个答案对我有意义。什么是对的?为什么?
How would the tests for an empty and full stack change if the first stack element was placed in the last array element (index one less than the array length) instead of the first array element(index 0)? (Drawing a picture of the stack will help)
A. Empty: top == length; Full: top == 0
B. Empty: top == 0; Full: top == length
C. Empty: top == length; Full: top == -1
D. Empty: top == length -1; Full: top == 0
What I have tried:
not sure which is right. it is a simple multiple choice question, but none of the answers make sense to me. what is right? and why?
推荐答案
画一幅画堆栈的帮助
所以......试一试。使用铅笔和纸绘制每种类型的图片,然后尝试。添加项目。删除它们。检查是否空。这应该是相当明显的!
So ... give it a try. Draw a picture of each type using a pencil and paper, and try it. Add items. Remove them. Check for empty. It should be fairly obvious!
这篇关于关于堆栈的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!