Yes. When you come to implementing this, you would probably use a zero based array (index numbers start from 0) so the top pointer would need to start at a value that did not reference an element of the array. -1 therefore makes sense. If you were using a 1 based array you could code it as described in the video. This video describes a VB.NET implementation which uses a 0 based array : kzitem.info/news/bejne/uq6IyKyHkKOboZw
@18kurama
7 жыл бұрын
Found it! So there's actually a video for its (stack) algorithm which you made. Thanks a lot! :)
@jivanjyotibhattacharyya558
4 жыл бұрын
top= maxsize or maxsize -1
@jivanjyotibhattacharyya558
4 жыл бұрын
as top starts from -1
@ComputerScienceLessons
4 жыл бұрын
It depends how you implement your stack. Normally, you would implement a stack with a zero based array, in which element numbering starts from zero (although some programming languages will let you set up a 1 (or more) based array). If your array is zero based, then you need to account for that in your code. What is important is that you are aware of the issue and you are consistent. To be honest though, if I was coding a stack in VB.NET or C#, I would use the built in stack object that comes with the language. :)KD
Пікірлер: 18