Which type of data structure is a stack?

こ雲淡風輕ζ 提交于 2021-02-04 20:55:29

问题


I got one simple question: which kind of data structure is a stack? Is it a static or dynamic data structure? I was looking for the answer and couldn't find it, therefore I got my own "explanation" - I guess, when you can implement it either by using an array or a linked list, it can be... both?, depending on implementation? Does my reasoning make any sense?


回答1:


By definition, a static data structure has fixed size. If you can limit the size of your stack to some pre-determined number, your stack becomes a static data structure. Its size is the size of its storage, plus the size of the stack pointer or stack index indicating the current location.

A stack of an unlimited capacity is a dynamic data structure, regardless of its implementation. It could be implemented with a linked list or an array that you re-allocate upon reaching its capacity, but the size of such stack changes as you add or remove data.




回答2:


Well, first of all, Stack is a data structure on its own. Stack are to be expandable which ever implementation used. Although stack can be fixed in size, maximum number of element it can contain. but often you will like to consider it as a dynamic structure that expands as the number of elements increase. Often it comes as ADT(Abstract data type) so that which ever structure(LinkedList, Array, ArrayList etc) is used to implement it, its functions and attributes are always the same



来源:https://stackoverflow.com/questions/34913353/which-type-of-data-structure-is-a-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!